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:
Beans and Dependency Injection
Send an email using the SMTP protocol
Java Program to Implement D-ary-Heap
Java TreeMap vs HashMap
Java Program to implement Associate Array
RestTemplate Post Request with JSON
Introduction to Liquibase Rollback
Creating Docker Images with Spring Boot
Lập trình đa luồng với CompletableFuture trong Java 8
Lập trình đa luồng với Callable và Future trong Java
Java Program to Perform Stooge Sort
Python Program to Find the Sum of Natural Numbers
Luồng Daemon (Daemon Thread) trong Java
Python Program to Split a List Into Evenly Sized Chunks
Base64 encoding và decoding trong Java 8
Working with Tree Model Nodes in Jackson
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Guide to UUID in Java
New Stream Collectors in Java 9
Introduction to the Java ArrayDeque
Comparing Objects in Java
A Guide to Concurrent Queues in Java
SOAP Web service: Authentication trong JAX-WS
Java Program to Implement Hash Tables with Quadratic Probing
LIKE Queries in Spring JPA Repositories
A Comparison Between Spring and Spring Boot
Comparing Strings in Java
A Guide to the finalize Method in Java
Java Program to Implement Find all Back Edges in a Graph
Getting a File’s Mime Type in Java
Java Program to Implement Strassen Algorithm
Removing all duplicates from a List in Java