Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AuthenticationFailedException when using JNDI and JavaMail with SMTP auth

843830Apr 8 2005 — edited Mar 4 2009
Hi all - I've been banging my head on this one for awhile now - hopefully someone else has done this.

We are working in a servlet container (tomcat), and need obtain a mail session from JNDI. We do this as follows:
			Context initCtx = new InitialContext();
			Context envCtx = (Context) initCtx.lookup("java:comp/env");
			Session mailSession=(Session) envCtx.lookup("mailSession/trumpetinc");
so far so good. The jndi entry for the mail session is configured in server.xml as follows:
          <Resource name="mailSession/trumpetinc" scope="Shareable" type="javax.mail.Session"/>
          <ResourceParams name="mailSession/trumpetinc">
            <parameter>
              <name>mail.smtp.host</name>
              <value>mail.server.com</value>
            </parameter>
            <parameter>
              <name>mail.smtp.password</name>
              <value>ABCDEFG</value>
            </parameter>
            <parameter>
              <name>mail.smtp.user</name>
              <value>trumpet_kevin</value>
            </parameter>
	    <parameter>
	      <name>mail.smtp.auth</name>
	      <value>true</value>
	    </parameter>
          </ResourceParams>
With the above, whenever we hit Transport.send(msg), we got an AuthenticationFailedException thrown. I have run into this before with SMTP authentication, so I decided to try using the transport.sendMessage() method instead.

So, I get the transport:
Transport trans = mailSession.getTransport("smtp");
trans.connect();
Then I send my message using:
msg.saveChanges();
trans.sendMessage(msg, msg.getAllRecipients());
and finally, I close the transport:
trans.close();
Unfortunately, I'm still getting the exception. Is it possible that my connect() method is not picking up the JNDI properties set in the server.xml file (this seems likely)? If so, what's the best way for me to get those properties so I can set them explicitly in the connect() method?

Thanks in advance,

- Kevin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 1 2009
Added on Apr 8 2005
14 comments
583 views