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:
Shuffling Collections In Java
Java Program to Implement Adjacency List
Spring Cloud – Securing Services
Fixing 401s with CORS Preflights and Spring Security
Spring WebClient and OAuth2 Support
Java Program to Implement the Monoalphabetic Cypher
Lớp Properties trong java
HashSet trong Java hoạt động như thế nào?
Hướng dẫn Java Design Pattern – Object Pool
Convert String to Byte Array and Reverse in Java
Java Program to Implement Karatsuba Multiplication Algorithm
Tính kế thừa (Inheritance) trong java
Spring 5 Functional Bean Registration
Spring Cloud Connectors and Heroku
Collect a Java Stream to an Immutable Collection
Guide to @ConfigurationProperties in Spring Boot
Java Program to Implement Horner Algorithm
Java Program to Implement Double Order Traversal of a Binary Tree
Java Program to Check Whether Topological Sorting can be Performed in a Graph
The “final” Keyword in Java
Working with Tree Model Nodes in Jackson
Java Program to Implement Queue using Linked List
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Giới thiệu Aspect Oriented Programming (AOP)
Java Program to Implement Sorted Circular Doubly Linked List
Java Streams vs Vavr Streams
Java Program to Implement Weight Balanced Tree
Java Program to Implement Rolling Hash
Pagination and Sorting using Spring Data JPA
Java Program to Implement Sorted Doubly Linked List
Introduction to Using FreeMarker in Spring MVC
Java Program to Implement a Binary Search Tree using Linked Lists