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"