Debug JavaMail

At times, you may need to debug a JavaMail application. WebSphere Application Server - Express gives you the option to turn on the JavaMail debugging feature. Using this option, the JavaMail API prints interactions with the mail servers and the properties of the mail session to the Java virtual machine system out log file for your application server.

The mail debug feature is enabled on a per session basis. Perform these steps to enable the JavaMail debugging feature:

  1. Open the WebSphere Application Server administrative console. For more information, see Start the WebSphere administrative console in the Administration topic.
  2. In the topology tree, expand Resources, and click Mail Providers.
  3. Click the mail session you want to work with.
  4. Click Mail Session, and click the mail session you want to work with.
  5. Click Debug. Debug is enabled only for this session.
  6. Click Apply or OK.
  7. Click Save in the toolbar to save changes to the configuration.

Once you have enabled debugging for JavaMail, the JavaMail APIs log the interactions between JavaMail applications and the e-mail server to the SystemOut Java virtual machine log file for the application server. See the JVM log files topic for more information on configuring and viewing JVM log files.

A sample of the JavaMail debugging output is as follows:

DEBUG: not loading system providers in <java.home>/lib
DEBUG  not loading optional custom providers file: /META-INF/javamail.providers
DEBUG: successfully loaded default providers
 
DEBUG  Tables of loaded providers 
DEBUG: Providers listed by Class Name:
{com.sun.mail.smtp.SMTPTransport=javax.mail.Provider
   [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider
   [STORE,imap,com.sun.mail.imap.IMAPStore,Sun
Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider
   [STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc]}
DEBUG:  Providers Listed By Protocol:
{imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems,
Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc], smtp=javax.mail.Provider
   [TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]}
DEBUG: not loading optional address map file: /META-INF/javamail.address.map
*** In SessionFactory.getObjectInstance,
  The default SessionAuthenticator is based on:
   store_user = john_smith
   store_pw = abcdef 
*** In SessionFactory.getObjectInstance, parameters in the new session:
    mail.store.protocol="imap"
    mail.transport.protocol="smtp"
    mail.imap.user="john_smith"
    mail.smtp.host="smtp.coldmail.com"
    mail.debug="true" 
    ws.store.password="abcdef"
    mail.from="john_smith@coldmail.com"
    mail.smtp.class="com.sun.mail.smtp.SMTPTransport"
    mail.imap.class="com.sun.mail.imap.IMAPStore"
    mail.imap.host="coldmail.com"
DEBUG: mail.smtp.class property exists and points to com.sun.mail.smtp.SMTPTransport
DEBUG SMTP: useEhlo true, useAuth false
DEBUG: SMTPTransport trying to connect to host "smtp.coldmail.com", port 25    

javax.mail.SendFailedException: Sending failed; 
      nested exception is:
      javax.mail.MessagingException: Unknown SMTP host: smtp.coldmail.com;
       nested exception is
       java.net.UnknownHostException: smtp.coldmail.com
       at javax.mail.Transport.send0(Transport.java:219) 
       at javax.mail.Transport.send(Transport.java:81)
       at ws.mailfvt.SendSaveTestCore.runAll(SendSaveTestCore.java:48)
       at testers.AnyTester.main(AnyTester.java:130)

This sample output illustrates a connection failure to a Simple Mail Transfer Protocol (SMTP) server because a fictitious name, smtp.coldmail.com, is specified as the server name.

The following are tips on how to read the debugging output: