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:
Converting Iterator to List
Cài đặt và sử dụng Swagger UI
Remove All Occurrences of a Specific Value from a List
Shuffling Collections In Java
4 tính chất của lập trình hướng đối tượng trong Java
Ignore Null Fields with Jackson
Read an Outlook MSG file
Java 8 Collectors toMap
Introduction to Spring Data REST
Spring Security Basic Authentication
Introduction to Spring Data JPA
String Joiner trong Java 8
How to Replace Many if Statements in Java
Java Program to Find the Mode in a Data Set
Java Timer
Java Program to Implement the Program Used in grep/egrep/fgrep
Write/Read cookies using HTTP and Read a file from the internet
Working with Kotlin and JPA
Python Program to Concatenate Two Lists
Python Program to Add Two Numbers
Java – InputStream to Reader
Java Program to Find Hamiltonian Cycle in an UnWeighted Graph
Java 14 Record Keyword
Java Program to Check Cycle in a Graph using Graph traversal
Java Program to Implement Max-Flow Min-Cut Theorem
Introduction to the Java NIO2 File API
Java Program to Implement Gift Wrapping Algorithm in Two Dimensions
Python Program to Find ASCII Value of Character
Base64 encoding và decoding trong Java 8
Hướng dẫn Java Design Pattern – Builder
Hướng dẫn Java Design Pattern – Null Object
Hướng dẫn Java Design Pattern – DAO