Debug a JavaMail ProgramTag(s): Networking
JavaMail Debug mode
To set the JavaMail Debug mode "on" :Session mailSession = Session.getDefaultInstance(props, null); mailSession.setDebug(true);
java -Dmail.debug=true ...
To redirect the JavaMail debugging output to a more appropriate log file you can
- link a PrintStream to a ByteArrayOutputStream,
- tell to JavaMail to use your PrintStream,
- do the JavaMail stuff,
- dump the the content of the ByteArrayOutputStream to your favorite logger.
ByteArrayOutputStream os = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(os); Session mailSession = Session.getDefaultInstance(props, null); try { if (MAIL_DEBUG) { logger.info("JAVAMAIL debug mode is ON"); mailSession.setDebug(true); mailSession.setDebugOut(ps); } ... transport.close(); if (MAIL_DEBUG) { logger.info(os); } } finally { ps.close(); os.close(); }
Verify connectivity to the MailServer with Telnet :
telnet mymailserver 25
Windows 7
By default, the telnet client is not installed on a Win7 workstation. To installed it, open command shell and type :
pkgmgr /iu:"TelnetClient"
Use a JavaMail server mock-up to act as "in-memory" mail server
See https://java.net/projects/mock-javamail and http://quintanasoft.com/dumbster/. These mock-ups are designed to act a mail server but the actual email is not delivered to the mail recipient which can be useful in a testing stage.
mail_outline
Send comment, question or suggestion to howto@rgagnon.com
Send comment, question or suggestion to howto@rgagnon.com