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:
Wiring in Spring: @Autowired, @Resource and @Inject
Java Program to Perform Encoding of a Message Using Matrix Multiplication
A Guide to Concurrent Queues in Java
Java Program to Implement Radix Sort
Java Program to Describe the Representation of Graph using Incidence Matrix
Java Program to Check whether Graph is a Bipartite using BFS
Java Program to Solve a Matching Problem for a Given Specific Case
Thao tác với tập tin và thư mục trong Java
Spring Cloud AWS – Messaging Support
Generating Random Numbers in a Range in Java
HttpClient Basic Authentication
Java Program to Implement Skip List
Python Program to Find Numbers Divisible by Another Number
Guide to ThreadLocalRandom in Java
Giới thiệu Json Web Token (JWT)
Java Program to Find the Number of Ways to Write a Number as the Sum of Numbers Smaller than Itself
ETL with Spring Cloud Data Flow
Java Program to Construct a Random Graph by the Method of Random Edge Selection
Sort a HashMap in Java
Java Program to Implement ArrayBlockingQueue API
Java Program to Find the Vertex Connectivity of a Graph
Java Program to Implement Queue using Two Stacks
Hướng dẫn Java Design Pattern – Adapter
Java Program to Implement Sorted Doubly Linked List
Java Program to Implement Floyd-Warshall Algorithm
Jackson – Bidirectional Relationships
Converting a Stack Trace to a String in Java
Java Program to Check whether Undirected Graph is Connected using DFS
Java Program to Find Shortest Path Between All Vertices Using Floyd-Warshall’s Algorithm
Configuring a DataSource Programmatically in Spring Boot
Hướng dẫn Java Design Pattern – Command
Reactive WebSockets with Spring 5