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 Implement Sorted Doubly Linked List
Jackson Unmarshalling JSON with Unknown Properties
Java Program to Perform Polygon Containment Test
Guide to Apache Commons CircularFifoQueue
Spring Cloud Series – The Gateway Pattern
Python Program to Get the Last Element of the List
The Thread.join() Method in Java
Checked and Unchecked Exceptions in Java
OAuth2 for a Spring REST API – Handle the Refresh Token in Angular
How to Count Duplicate Elements in Arraylist
Spring Data JPA Delete and Relationships
Handling Errors in Spring WebFlux
Spring Boot: Customize Whitelabel Error Page
Python Program Read a File Line by Line Into a List
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Câu lệnh điều khiển vòng lặp trong Java (break, continue)
Convert Time to Milliseconds in Java
Spring 5 WebClient
Configuring a DataSource Programmatically in Spring Boot
Introduction to Java 8 Streams
HttpClient with SSL
Python Program to Reverse a Number
Autoboxing và Unboxing trong Java
Spring MVC and the @ModelAttribute Annotation
Guide to Java 8’s Collectors
Guide to System.gc()
Convert String to Byte Array and Reverse in Java
Converting Strings to Enums in Java
Java Program to Implement Unrolled Linked List
Java Program to Find the Vertex Connectivity of a Graph
Java Program to Implement Euclid GCD Algorithm
Java Program to Describe the Representation of Graph using Adjacency Matrix