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:
Python Program to Generate a Random Number
Java Program to Generate All Possible Combinations Out of a, b, c, d, e
Simplify the DAO with Spring and Java Generics
Java Optional as Return Type
Java Program to Generate Random Numbers Using Middle Square Method
Getting Started with Stream Processing with Spring Cloud Data Flow
Daemon Threads in Java
Test a REST API with Java
Wiring in Spring: @Autowired, @Resource and @Inject
Jackson Date
Vector trong Java
Quick Guide to Spring Controllers
Spring Boot - Tomcat Deployment
Java Program to Implement Cubic convergence 1/pi Algorithm
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Java Concurrency Interview Questions and Answers
Spring Security Login Page with React
Server-Sent Events in Spring
Java Program to Find the Nearest Neighbor Using K-D Tree Search
Mệnh đề if-else trong java
Spring Boot - Application Properties
Guide to the Java Clock Class
Java Program to do a Breadth First Search/Traversal on a graph non-recursively
Java Program to Perform Partition of an Integer in All Possible Ways
Java Program to Implement ConcurrentLinkedQueue API
Spring Security 5 for Reactive Applications
Guide to UUID in Java
Guide to Guava Multimap
Java – Byte Array to Reader
Java Program to Implement Rolling Hash
Java Program to Implement Hash Tables with Linear Probing
Java Program to Find Nearest Neighbor for Dynamic Data Set