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:
Java Program to Sort an Array of 10 Elements Using Heap Sort Algorithm
Introduction to Spring Data MongoDB
Python Program to Slice Lists
Java Program to Construct a Random Graph by the Method of Random Edge Selection
Python Program to Print all Prime Numbers in an Interval
Query Entities by Dates and Times with Spring Data JPA
Getting Started with Forms in Spring MVC
HttpClient 4 – Send Custom Cookie
Java Program to Check if a Matrix is Invertible
Java Program to Check for balanced parenthesis by using Stacks
Java NIO2 Path API
Registration – Password Strength and Rules
Java Program to Implement the Vigenere Cypher
Xử lý ngoại lệ trong Java (Exception Handling)
Spring Boot - Eureka Server
Java Program to Implement Skew Heap
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Display Auto-Configuration Report in Spring Boot
Functional Interfaces in Java 8
Hướng dẫn sử dụng Java Generics
Python Program to Make a Flattened List from Nested List
Guide to the Synchronized Keyword in Java
Java Program to Implement Sieve Of Eratosthenes
Java Program to Implement Floyd Cycle Algorithm
Daemon Threads in Java
Hướng dẫn sử dụng lớp Console trong java
Using the Map.Entry Java Class
Merging Two Maps with Java 8
Introduction to Spliterator in Java
Spring Boot - Web Socket
Giới thiệu Design Patterns
ETags for REST with Spring