Skip to Content
author's profile photo Former Member
Former Member

Using JavaMail from Portal Service

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Jan 20, 2005 at 12:47 PM

    Hi Nick,

    first question is why you try to use POP3 to send mail??? POP3 is a protocol to retrieve incoming mails, for sending mails you normally use SMTP.

    Second question is if there is any need for you to reinvent the wheel. A portal installation has different possibilities to send mail (depending if you have KM installed).

    For example, see the following applications on Netweaver EP6 and the given API's within them:

    com.sap.netweaver.coll.appl.gw -- transjavamail_api

    com.sap.netweaver.coll.appl.gw -- srvcmail_api

    com.sap.netweaver.coll.shared -- gw_api

    (gw is Groupware)

    com.sap.netweaver.bc.uti -- public_api (using channels)

    Last question is, why you don't say "thank you" the SDN way... Maybe you don't know. Just press the yellow star button at helpful replies and choose the corresponding amount of points. Be sure, no one will debit these points directly from you bank account. It's totally harmless, just give it a try... 😊

    Once you have done, you will feel good, better than before. To feel best, also consider doing it on these threads:

    InputField width = X%

    Use of Enter in toolbars/forms

    Lifespan of popup window

    Hope it helps

    Detlev

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Samar,

      at least you need access to the deployed applications, if under WEB-INF/deployment/temp (where you'll find the PARs) or under WEB-INF/portal/portalapps (where you'll find the deployed "internal" part, especially all the java coding).

      If you don't have access to the OS, you can download such stuff via System Admin - Support - Support Desk - Portal Runtime - Browse Deployment. From there you can download complete DIRs as zip.

      Hope it helps

      Detlev

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2007 at 07:19 AM

    Hello out there,

    got the same problem. When performing lookup for "java:comp/env/mail/MailSession" with "javax.naming.InitialContext", an object is returned and in debug-mode all signs indicate that this object is of type "javax.mail.Session". But when an explicit cast to this type is done a "ClassCastException" without detailed message is thrown. Here's the coding:

    try {
      Context initialContext = new InitialContext();
      Object o = initialContext.lookup(mm_jndiName);
      mm_session = (javax.mail.Session) o;
    } catch (Throwable t) {
      // here the "empty" ClassCastException is caught
    }
    

    Does anybody has an idea what may be the problem?

    edit: the narrow method "PortableRemoteObject.narrow" does not work either

    thx

    Message was edited by:

    Sascha Lauck

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.