Friday, 3 July 2009

JavaMail on WebSphere

Creating a mail resource - whereby you use JNDI to get a context that you send email through - is surprisingly easy in WebSphere, at least for my minimal requirements :-)

I reused the Built-in Mail Provider @ server level:

...and then created my own mail session:

Mail Providers > Built-in Mail Provider > Mail Sessions

  • Name = MyMailSession
  • JNDI name = mail/MyMailSessionMail
  • transport host = 192.168.192.5
  • Mail transport user ID = wiki
  • Mail transport password = wiki
  • Enable debug mode = ticked

Next I created a very simple servlet, whose doGet method grabs the JNDI context and then uses the JavaMail API to send an email:

I pulled in the JNDI reference straight from the web container, but I could have used an environmental reference from the web.xml file:

Because the SMTP debugging was on I got output that looked like the following and that resulted in an email being sent to me :-)

NOTE: a useful reference is at http://www.ibm.com/developerworks/websphere/library/techarticles/0310_fung_yu/fung_yu.html

0 comments:

Post a Comment