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:
Hướng dẫn sử dụng biểu thức chính quy (Regular Expression) trong Java
Java Program to Implement Gale Shapley Algorithm
Java – Write to File
Convert String to int or Integer in Java
A Guide to ConcurrentMap
Java Program to Implement RenderingHints API
Java Program to Implement Pagoda
Spring Security and OpenID Connect
Giới thiệu thư viện Apache Commons Chain
Java Program to Implement Suffix Array
Python Program to Convert Kilometers to Miles
Getting Started with Stream Processing with Spring Cloud Data Flow
Java Program to Implement the Hungarian Algorithm for Bipartite Matching
Java Program to Find MST (Minimum Spanning Tree) using Kruskal’s Algorithm
Giới thiệu HATEOAS
Introduction to Spring Method Security
Java Program to Check whether Directed Graph is Connected using DFS
Spring Data Java 8 Support
Convert a Map to an Array, List or Set in Java
Spring Boot Configuration with Jasypt
Java Program to Generate Random Partition out of a Given Set of Numbers or Characters
Java Program to Check Whether Topological Sorting can be Performed in a Graph
Java Program to Implement Gauss Jordan Elimination
Java Program to find the maximum subarray sum O(n^2) time(naive method)
Java Scanner hasNext() vs. hasNextLine()
Java Program to Implement Binary Heap
Composition, Aggregation, and Association in Java
Java Program to Compute the Area of a Triangle Using Determinants
LIKE Queries in Spring JPA Repositories
Enum trong java
Java Program to Check if it is a Sparse Matrix
Toán tử instanceof trong java