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:
Java Program to Implement Horner Algorithm
Java Program to Implement Stack API
Java Program to Check whether Undirected Graph is Connected using DFS
Java Program to Implement HashSet API
Java Program to Find the Vertex Connectivity of a Graph
Introduction to Spring Boot CLI
Guide to the Fork/Join Framework in Java
Spring Boot - Zuul Proxy Server and Routing
A Guide to LinkedHashMap in Java
Send email with SMTPS (eg. Google GMail)
Overview of the java.util.concurrent
Introduction to the Java ArrayDeque
Jackson – Unmarshall to Collection/Array
Spring Boot - Batch Service
Java Program to Check Whether Topological Sorting can be Performed in a Graph
Java Program to Perform the Sorting Using Counting Sort
Java Program to Implement Brent Cycle Algorithm
Java Program to Find Maximum Element in an Array using Binary Search
Guide to Character Encoding
Shuffling Collections In Java
Spring WebFlux Filters
Examine the internal DNS cache
Spring Boot - Exception Handling
Python Program to Concatenate Two Lists
Xây dựng ứng dụng Client-Server với Socket trong Java
Spring Boot - Admin Server
Java Program to Implement Coppersmith Freivald’s Algorithm
Phương thức forEach() trong java 8
Finding the Differences Between Two Lists in Java
How to Convert List to Map in Java
Python Program to Compute the Power of a Number
Python Program to Find Armstrong Number in an Interval