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:
Java Program to find the maximum subarray sum using Binary Search approach
Toán tử trong java
Java Switch Statement
Converting Iterator to List
Java Program to Implement Quick Sort Using Randomization
A Guide to the finalize Method in Java
Encode a String to UTF-8 in Java
Java Program to Implement Sieve Of Eratosthenes
Python Program to Get File Creation and Modification Date
A Guide to Java SynchronousQueue
Java Program to Check Whether a Given Point is in a Given Polygon
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Reactive WebSockets with Spring 5
Python Program to Compute all the Permutation of the String
Convert Hex to ASCII in Java
Java Program to implement Sparse Vector
Java Program to Solve Set Cover Problem assuming at max 2 Elements in a Subset
Convert Hex to ASCII in Java
Java Program to Implement EnumMap API
Checking for Empty or Blank Strings in Java
Sử dụng CountDownLatch trong Java
Python Program to Find Hash of File
So sánh ArrayList và LinkedList trong Java
Adding Parameters to HttpClient Requests
Assertions in JUnit 4 and JUnit 5
Handle EML file with JavaMail
Convert Character Array to String in Java
Java Program to Print only Odd Numbered Levels of a Tree
Apache Commons Collections MapUtils
Constructor Injection in Spring with Lombok
Encode/Decode to/from Base64
Java Program to Implement AA Tree