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:
Hướng dẫn Java Design Pattern – Facade
Spring MVC and the @ModelAttribute Annotation
New Features in Java 14
Java InputStream to Byte Array and ByteBuffer
Apache Camel with Spring Boot
Java Program to Generate All Pairs of Subsets Whose Union Make the Set
Send an email using the SMTP protocol
Java Program to Implement LinkedList API
Java Program to Implement Bresenham Line Algorithm
The Dining Philosophers Problem in Java
Spring Cloud – Tracing Services with Zipkin
Java Program to Implement CopyOnWriteArraySet API
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Inheritance with Jackson
Python Program to Convert Celsius To Fahrenheit
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Java Program to Find Transpose of a Graph Matrix
Array to String Conversions
Java 9 Stream API Improvements
Converting Java Date to OffsetDateTime
Java Program to Implement Borwein Algorithm
Working with Kotlin and JPA
Shuffling Collections In Java
Consuming RESTful Web Services
Java Program to Implement Hash Tables Chaining with Doubly Linked Lists
Java Program to Check if any Graph is Possible to be Constructed for a Given Degree Sequence
Java Program to Implement Stack API
Spring Boot with Multiple SQL Import Files
RestTemplate Post Request with JSON
Remove HTML tags from a file to extract only the TEXT
The Guide to RestTemplate
Java Program to Perform Finite State Automaton based Search