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:
Guide to the Java Clock Class
Spring @RequestMapping New Shortcut Annotations
Spring Boot - Apache Kafka
Java Program to do a Depth First Search/Traversal on a graph non-recursively
Spring Boot with Multiple SQL Import Files
Apache Commons Collections Bag
Java Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers
Java Program to Implement Find all Back Edges in a Graph
Spring Boot Tutorial – Bootstrap a Simple Application
Quick Intro to Spring Cloud Configuration
Lập trình mạng với java
Python Program to Find Hash of File
HttpClient 4 Cookbook
New in Spring Security OAuth2 – Verify Claims
Hướng dẫn Java Design Pattern – Facade
HashMap trong Java hoạt động như thế nào?
A Guide to Apache Commons Collections CollectionUtils
Stack Memory and Heap Space in Java
A Guide to Iterator in Java
Ways to Iterate Over a List in Java
Send an email with an attachment
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Concatenating Strings In Java
@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
Spring 5 Testing with @EnabledIf Annotation
Java Program to Implement SynchronosQueue API
Java Program to Implement Leftist Heap
Java Program to Perform Searching Based on Locality of Reference
Java Program to Find Inverse of a Matrix
Service Registration with Eureka
Initialize a HashMap in Java
Spring Cloud Connectors and Heroku