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:
Copy a List to Another List in Java
Composition, Aggregation, and Association in Java
Python Program to Convert Two Lists Into a Dictionary
Spring Boot - Cloud Configuration Client
An Intro to Spring Cloud Security
Spring Boot - Admin Client
Map Interface trong java
A Guide to the ViewResolver in Spring MVC
Guava – Join and Split Collections
Giới thiệu Json Web Token (JWT)
Java Program to Implement Sorting of Less than 100 Numbers in O(n) Complexity
Iterating over Enum Values in Java
Spring Boot Tutorial – Bootstrap a Simple Application
Java Program to Implement Solovay Strassen Primality Test Algorithm
Spring Boot - Flyway Database
Retrieve User Information in Spring Security
Java Program to Implement Counting Sort
Concrete Class in Java
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Logout in an OAuth Secured Application
Java Program to Implement Johnson’s Algorithm
Java Program to Implement Bubble Sort
Java Program to Implement Quick Sort Using Randomization
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
Spring Boot - Tomcat Port Number
Java Program to find the peak element of an array using Binary Search approach
Java Program to Implement Pairing Heap
Easy Ways to Write a Java InputStream to an OutputStream
Java Program to Implement IdentityHashMap API
Java Program to Implement LinkedBlockingQueue API
Versioning a REST API
Comparing Long Values in Java