Skip to Content
0
Former Member
Jan 20, 2005 at 11:17 AM

Using JavaMail from Portal Service

92 Views

Hello,

I'm getting quite strange problem on attempt to use e-mail from portal service.

I tried several ways and all have failed.

First thing, which I tried was to include actual sun JavaMail API to libs of my service and use quite "java-like" method to send e-mail:

// props initialization

...

//

Session session = Session.getDefaultInstance(props);

Provider[] providers = session.getProviders();

Store store = session.getStore("pop3");

...

I see that providers are properly initialized, however last line throws "NoSuchProviderException" due to the fact (debug in Session class shows it), that it find POP3Store class, but it has no constructor with parameters "Session" and "URLName". So NoSuchMethodException is thrown and then converted to "NoSuchProviderException".

Ok, I thought that the classpath of portal service may include different version of mail.jar and found one in my SAP WAS installation (it's really different and quite old - SP7 WAS includes mail.jar from year 2000).

Nevertheless update of mail.jar in my project doesn't help - I get absolutely the same exception.

I looked in the forum and found that mail session should be instantiated by lookup in J2EE:

Session session = (Session) initialContext.lookup("java:comp/env/mail/MailSession");

Here I see that lookup performed good (it returns an object of type "javax.mail.Session", but it could not be casted to "javax.mail.Session" (because the classes are from different classloaders).

My last attempt was to use narrow for classcasting:

Session session = (Session) javax.rmi.PortableRemoteObject.narrow(initialContext.lookup("java:comp/env/mail/MailSession"), Session.class);

it doesn't work either - narrow throws ClassCastException too.

Note: all attempts I did with mail.jar in lib folder of my portal (otherwise I get "ClassNotFoundException" in runtime for javax.mail.MessagingException on initialization of my service.

No sharing references were specified in portalapp.xml (I don't know if I should add any).

What did I do wrong?

Any help will be appreciated. As current workaround I've implemented servlet, which works perfectly (code is just copied to servlet, no mail.jar in the servlet project - as it's somehow found in runtime).

My portal service is developed as DC, if a library has to be added in references, please let me know what should I add to "Used DCs"

Thank you!

Best regards,

Nick