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:
Mockito and JUnit 5 – Using ExtendWith
Java Program to Implement Slicker Algorithm that avoids Triangulation to Find Area of a Polygon
Using Custom Banners in Spring Boot
Java equals() and hashCode() Contracts
Setting Up Swagger 2 with a Spring REST API
Java Program to Perform Right Rotation on a Binary Search Tree
A Quick Guide to Spring Cloud Consul
Using JWT with Spring Security OAuth (legacy stack)
Java 9 Stream API Improvements
Python Program to Capitalize the First Character of a String
A Guide to EnumMap
Hướng dẫn kết nối cơ sở dữ liệu với Java JDBC
Giới thiệu Json Web Token (JWT)
Java Program to Implement Find all Forward Edges in a Graph
Python Program to Sort Words in Alphabetic Order
Collection trong java
Migrating from JUnit 4 to JUnit 5
Python Program to Access Index of a List Using for Loop
Chuyển đổi giữa các kiểu dữ liệu trong Java
Java Streams vs Vavr Streams
Sorting Query Results with Spring Data
Java Program to Implement Counting Sort
Spring Boot - Apache Kafka
Python Program to Check Leap Year
HandlerAdapters in Spring MVC
A Guide to the Java LinkedList
Limiting Query Results with JPA and Spring Data JPA
Spring Data MongoDB – Indexes, Annotations and Converters
Java Program to Implement Warshall Algorithm
Java Program to Implement Gauss Jordan Elimination
Difference Between Wait and Sleep in Java
Adding Parameters to HttpClient Requests