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:
Logout in an OAuth Secured Application
Using the Map.Entry Java Class
Configuring a DataSource Programmatically in Spring Boot
A Guide to System.exit()
Java Program to Delete a Particular Node in a Tree Without Using Recursion
Primitive Type Streams in Java 8
Converting a List to String in Java
Posting with HttpClient
Java Program to Generate All Possible Combinations of a Given List of Numbers
Xử lý ngoại lệ trong Java (Exception Handling)
Java Program to Implement the RSA Algorithm
Java Program to Implement Cubic convergence 1/pi Algorithm
Lập trình đa luồng với CompletableFuture trong Java 8
Apache Commons Collections OrderedMap
Introduction to Java 8 Streams
Java Program to Use Above Below Primitive to Test Whether Two Lines Intersect
Generating Random Dates in Java
Java Program to Implement Lloyd’s Algorithm
Python Program to Print the Fibonacci sequence
Java Program to Implement Heap
Tìm hiểu về xác thực và phân quyền trong ứng dụng
A Guide to Concurrent Queues in Java
Java Program to Implement Gauss Jordan Elimination
Python Program to Get the Last Element of the List
Java Multi-line String
Guide to the ConcurrentSkipListMap
Summing Numbers with Java Streams
Jackson vs Gson
Python Program to Merge Mails
Java Program to Implement Fisher-Yates Algorithm for Array Shuffling
Tạo chương trình Java đầu tiên sử dụng Eclipse
Introduction to Spring Cloud Stream