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 Implement ScapeGoat Tree
Difference Between Wait and Sleep in Java
Properties with Spring and Spring Boot
Lập trình đa luồng trong Java (Java Multi-threading)
Hướng dẫn Java Design Pattern – Template Method
Working With Maps Using Streams
Spring Boot - Enabling HTTPS
Quick Guide to @RestClientTest in Spring Boot
Java Web Services – JAX-WS – SOAP
Java Program to Convert a Decimal Number to Binary Number using Stacks
Bootstrapping Hibernate 5 with Spring
Java Program to find the maximum subarray sum using Binary Search approach
Setting a Request Timeout for a Spring REST API
Split a String in Java
Spring Boot - Exception Handling
The “final” Keyword in Java
A Guide to the ViewResolver in Spring MVC
Assert an Exception is Thrown in JUnit 4 and 5
Tránh lỗi ConcurrentModificationException trong Java như thế nào?
Java – Write a Reader to File
Chuyển đổi từ HashMap sang ArrayList
An Intro to Spring Cloud Task
Java – Convert File to InputStream
Truyền giá trị và tham chiếu trong java
Java Program to Implement the Monoalphabetic Cypher
Spring Boot - Google Cloud Platform
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Java Program to Perform Polygon Containment Test
Python Program to Add Two Matrices
Java Program to Perform Naive String Matching
Mapping a Dynamic JSON Object with Jackson
Sao chép các phần tử của một mảng sang mảng khác như thế nào?