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:
A Guide to the finalize Method in Java
Exploring the Spring Boot TestRestTemplate
Introduction to Spring Boot CLI
Spring MVC Content Negotiation
How to Count Duplicate Elements in Arraylist
Quick Guide to Spring MVC with Velocity
Remove the First Element from a List
Java Program to Perform Cryptography Using Transposition Technique
Java Program to Implement Word Wrap Problem
How to Read a Large File Efficiently with Java
Java List UnsupportedOperationException
@Order in Spring
Giới thiệu java.io.tmpdir
Java Program to Implement Doubly Linked List
Java Program to Implement AVL Tree
Java Program to Implement Quick Sort Using Randomization
Custom Error Pages with Spring MVC
Java Program to Find the Median of two Sorted Arrays using Binary Search Approach
Python Program to Illustrate Different Set Operations
Hướng dẫn Java Design Pattern – Bridge
Java Program to Implement an Algorithm to Find the Global min Cut in a Graph
Spring Security Remember Me
Immutable Objects in Java
Sử dụng CountDownLatch trong Java
Java Program to Implement the MD5 Algorithm
Java Program to Search Number Using Divide and Conquer with the Aid of Fibonacci Numbers
Java Program to Implement vector
Spring WebClient and OAuth2 Support
StringBuilder vs StringBuffer in Java
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Python Program to Safely Create a Nested Directory
Testing an OAuth Secured API with Spring MVC