InfoCenter Home >
4: Developing applications >
4.6: Java Technologies >
4.6.1: Using JavaMail >
4.6.1.3: Debugging JavaMail

4.6.1.3: Debugging JavaMail

There will be times when you need to debug your JavaMail applications. One option is to turn on JavaMail's debugging feature. With this option on, JavaMail will print to stdout its interactions with the mail servers. These interactions are printed in detail, in a step-by-step format.

   With WebSphere Application Server, stdout and stderr are usually redirected to files. The specific file paths can be set with an application server's Properties > File panel. For example, for the Default Server, stdout is redirected by default to the file:
<WAS_HOME>\logs\default_server_stdout.log

Enable debugging programmatically, or through the command line.

  • The easiest way to turn on debugging is to call method setDebug() on the mail session after session is obtained through a JNDI lookup, as shown below:
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();
    mail_session = (javax.mail.Session) ctx.lookup("java:comp/env/mail/MailSession");
    mail_session.setDebug(true);
    ...
    This debugging approach requires re-compiling and, very likely, re-loading the application component in which this code is embedded. This approach may be impractical at times.

    You can also edit the startServerBasic.bat file on Windows NT or startServerBasic.sh file on UNIX platforms and add the following flag to the line that starts the Java program:

    -Dmail.debug=true
  • If your JavaMail code is in a Java client which is invoked from the command line, add the -Dmail.debug=true flag to the java command, and the debugging output will be displayed in the command window.
  •    Property mail.debug, set with the last two approaches, is shared by all mail session instances within the same JVM process. When debugging is enabled in this manner, JavaMail will print out step-by-step, mail-related interactions to stdout for all these mail sessions.

The output in stdout looks like the following example:


...


DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp]
DEBUG SMTP: useEhlo true, useAuth false

DEBUG: SMTPTransport trying to connect to host "smtp3.eedge.com", port 25

DEBUG SMTP RCVD: 220 relay14.eedge.com ESMTP Sendmail; Tue, 19 Dec 2000 15:08:42 -0700

DEBUG: SMTPTransport connected to host "smtp3.eedge.com", port: 25

DEBUG SMTP SENT: EHLO y2001
DEBUG SMTP RCVD: 250-relay14.eedge.com Hello testpc.eedge.com, pleased to meet you
250-8BITMIME
250-SIZE 20000000
250-DSN
250-ONEX
250-ETRN
250-XUSR
250 HELP


DEBUG SMTP SENT: MAIL FROM:<alice@mail.eedge.com>
DEBUG SMTP RCVD: 250 <alice@mail.eedge.com>... Sender ok


DEBUG SMTP SENT: RCPT TO:<bob@coldmail.net>
DEBUG SMTP RCVD: 250 <bob@coldmail.net>... Recipient ok


Verified Addresses
bob@coldmail.net
DEBUG SMTP SENT: DATA
DEBUG SMTP RCVD: 354 Enter mail, end with "." on a line by itself


DEBUG SMTP SENT:
...
DEBUG SMTP RCVD: 250 PAA125654 Message accepted for delivery


DEBUG SMTP SENT: QUIT

Go to previous article: Configuring JavaMail Go to next article: Running the JavaMail sample

 

 
Go to previous article: Configuring JavaMail Go to next article: Running the JavaMail sample