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:
RegEx for matching Date Pattern in Java
Concrete Class in Java
Using Java Assertions
Python Program to Capitalize the First Character of a String
Java Program to Implement Gauss Jordan Elimination
Java Program to Implement Ternary Search Algorithm
Hướng dẫn Java Design Pattern – MVC
Java Program to Implement Heap
Python Program to Get the Last Element of the List
Send an email using the SMTP protocol
Java Program to Implement Radix Sort
Spring WebFlux Filters
Từ khóa throw và throws trong Java
Java Program to Implement Weight Balanced Tree
Spring Boot - Enabling HTTPS
Java Program to Perform Matrix Multiplication
Fixing 401s with CORS Preflights and Spring Security
Python Program to Get the Full Path of the Current Working Directory
Hướng dẫn Java Design Pattern – Proxy
Spring @RequestMapping New Shortcut Annotations
Java Program to Implement Disjoint Set Data Structure
JUnit 5 @Test Annotation
Java – Generate Random String
RestTemplate Post Request with JSON
Lớp Collectors trong Java 8
Hướng dẫn Java Design Pattern – Command
Java Program to Implement Uniform-Cost Search
Convert Character Array to String in Java
Python Program to Compute the Power of a Number
Spring Boot - Database Handling
A Guide to LinkedHashMap in Java
Giới thiệu luồng vào ra (I/O) trong Java