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!

Using JavaMail with Tomcat and JNDI

843830Apr 6 2003 — edited Apr 7 2003
I have a web application and I want to make use of JNDI Mail Sessions for sending email in my Web Appln.
I am using Tomcat4.0.1
In my server.xml file I declared a resource as follows:

<Resource name="mail/Session" auth="Container" type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>mail.abc.com</value>
</parameter>
</ResourceParams>

Now Inside my jsp/servlet code i can use something like this:=

// Acquire our JavaMail session object
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");

// Prepare our mail message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress dests[] = new InternetAddress[]
{ new InternetAddress(to) };
message.setRecipients(Message.RecipientType.TO, dests);
message.setSubject(subject);
message.setContent(content, "text/plain");

// Send our mail message
Transport.send(message);

But my smtp mail provider uses Authentication.
So I am looking of some way wherein I can provide the user and password information in the server.xml file itself along with smtp provider.

My Query is How to do this as i dont see any references for using JavaMail sessions using Authentication

Any Help highly appreciated
Thanks
Raj
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2003
Added on Apr 6 2003
1 comment
405 views