1. JavaMail Debug mode
To set the JavaMail Debug mode “on” :
Session mailSession = Session.getDefaultInstance(props, null); mailSession.setDebug(true);
or set the property when launching the JVM:
java -Dmail.debug=true ...
This setting puts the JavaMail classes in debug mode mode to System.out.
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 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();
}
2. Verify connectivity to the MailServer with Telnet:
telnet mymailserver 25
For example, you can detect if your firewall is blocking your connection.
By default, the telnet client is not installed on a Win7 workstation. To install it, open the command shell and type:
pkgmgr /iu:"TelnetClient"
You can also install it through the Control Panel, see Microsoft Technet.
Done! Happy Coding!
Related posts:
XML Serialization and Deserialization with Jackson
Adding Shutdown Hooks for JVM Applications
Java Program to Perform Partial Key Search in a K-D Tree
Converting a Stack Trace to a String in Java
HttpClient 4 Cookbook
A Guide to Iterator in Java
Comparing Strings in Java
Spring Security 5 for Reactive Applications
The Dining Philosophers Problem in Java
Java IO vs NIO
Consumer trong Java 8
A Guide to BitSet in Java
Spring RestTemplate Error Handling
JUnit 5 @Test Annotation
Spring Security 5 – OAuth2 Login
Using Optional with Jackson
Java Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Implement Stack API
So sánh ArrayList và Vector trong Java
Java Program to Find Minimum Element in an Array using Linear Search
Spring Boot - Logging
An Introduction to Java.util.Hashtable Class
Java Program to Implement Network Flow Problem
Java Program to Implement Nth Root Algorithm
Convert Hex to ASCII in Java
Java Program to Find Number of Articulation points in a Graph
Java Program to Implement Find all Forward Edges in a Graph
Java Program to Generate a Sequence of N Characters for a Given Specific Case
Java Program to Implement AA Tree
Spring Data JPA Delete and Relationships
Hướng dẫn Java Design Pattern – DAO
Java Program to Use rand and srand Functions