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:
Exploring the New Spring Cloud Gateway
HTTP Authentification and CGI/Servlet
Explain about URL and HTTPS protocol
Python Program to Slice Lists
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Java Program to Encode a Message Using Playfair Cipher
Java Program to Implement Patricia Trie
Java Program to Solve any Linear Equation in One Variable
Logout in an OAuth Secured Application
Java InputStream to String
Java Program to Implement Splay Tree
Spring Boot - Apache Kafka
Hướng dẫn sử dụng String Format trong Java
Configure a RestTemplate with RestTemplateBuilder
Java Program to Implement ConcurrentHashMap API
Generic Constructors in Java
How to use the Spring FactoryBean?
Hướng dẫn Java Design Pattern – Flyweight
Guide to PriorityBlockingQueue in Java
Finding the Differences Between Two Lists in Java
A Guide to EnumMap
Returning Custom Status Codes from Spring Controllers
Java Program to Implement Floyd-Warshall Algorithm
Java Program to Represent Graph Using Adjacency Matrix
How to Define a Spring Boot Filter?
Convert a Map to an Array, List or Set in Java
Removing all Nulls from a List in Java
Python Program to Check If a String Is a Number (Float)
Show Hibernate/JPA SQL Statements from Spring Boot
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Date Time trong Java 8
Spring Boot - Flyway Database