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:
Python Program to Shuffle Deck of Cards
Java – Write a Reader to File
Sử dụng JDBC API thực thi câu lệnh truy vấn dữ liệu
Python Program to Represent enum
Java Program to Compute DFT Coefficients Directly
How to Change the Default Port in Spring Boot
A Quick Guide to Spring MVC Matrix Variables
Java Program to Implement RenderingHints API
Converting a Stack Trace to a String in Java
Tính kế thừa (Inheritance) trong java
Introduction to Thread Pools in Java
Jackson Annotation Examples
Java Program to Implement the Vigenere Cypher
Spring Cloud – Tracing Services with Zipkin
Spring Data JPA @Query
An Introduction to Java.util.Hashtable Class
A Guide to @RepeatedTest in Junit 5
Java Program to Check Whether Graph is DAG
Java Program to Find Nearest Neighbor for Static Data Set
Java Program to Implement Stack API
New Features in Java 15
Spring Boot - Hystrix
Interface trong Java 8 – Default method và Static method
New in Spring Security OAuth2 – Verify Claims
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Java Program to Implement Min Hash
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays
How to Convert List to Map in Java
Java Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
What is Thread-Safety and How to Achieve it?
File Upload with Spring MVC
Sorting in Java