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:
Sorting in Java
Java Program to Find a Good Feedback Edge Set in a Graph
Java Program to Implement Suffix Array
Introduction to Spring Cloud Rest Client with Netflix Ribbon
Java Program to Implement Attribute API
Java Program to Compute Cross Product of Two Vectors
Guide to Mustache with Spring Boot
Hướng dẫn Java Design Pattern – Strategy
Java Program to Implement Doubly Linked List
Logging a Reactive Sequence
Spring’s RequestBody and ResponseBody Annotations
Python Program to Safely Create a Nested Directory
A Guide to Iterator in Java
Java Program to Describe the Representation of Graph using Incidence List
Java Program to Implement Strassen Algorithm
HandlerAdapters in Spring MVC
Annotation trong Java 8
Reading an HTTP Response Body as a String in Java
Java Program to Implement Stack API
Spring Boot - Thymeleaf
Hướng dẫn sử dụng lớp Console trong java
Spring WebClient Requests with Parameters
Spring Security Basic Authentication
Java Program to Implement Meldable Heap
An Intro to Spring Cloud Zookeeper
Python Program to Print Colored Text to the Terminal
Java Program to Implement Segment Tree
Python Program to Count the Number of Occurrence of a Character in String
Java Program to Implement Gale Shapley Algorithm
Logout in an OAuth Secured Application
Iterating over Enum Values in Java
Sử dụng Fork/Join Framework với ForkJoinPool trong Java