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:
Serialization và Deserialization trong java
Java Program to Perform the Sorting Using Counting Sort
Java Program to Implement Merge Sort Algorithm on Linked List
Spring Boot - Scheduling
Guide to Apache Commons CircularFifoQueue
Add Multiple Items to an Java ArrayList
Java Program to Implement Sorted Singly Linked List
Java 8 StringJoiner
Java Program to Implement Word Wrap Problem
Mệnh đề Switch-case trong java
Python Program to Trim Whitespace From a String
Performance Difference Between save() and saveAll() in Spring Data
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Hamcrest Collections Cookbook
Spring Boot - Admin Server
Java Program to Implement Counting Sort
Control Structures in Java
Spring Security Custom AuthenticationFailureHandler
Java 8 Stream findFirst() vs. findAny()
The Spring @Controller and @RestController Annotations
Java Program to Create a Minimal Set of All Edges Whose Addition will Convert it to a Strongly Conne...
Spring Boot - Database Handling
Từ khóa static và final trong java
Java Program to Check the Connectivity of Graph Using DFS
Serialize Only Fields that meet a Custom Criteria with Jackson
Java Program to Implement PriorityQueue API
How to Break from Java Stream forEach
Hướng dẫn Java Design Pattern – Transfer Object
Java Program to implement Priority Queue
Creating a Custom Starter with Spring Boot
Tránh lỗi NullPointerException trong Java như thế nào?
ExecutorService – Waiting for Threads to Finish