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:
Python Program to Access Index of a List Using for Loop
Java Program to Implement PriorityBlockingQueue API
Python Program to Count the Occurrence of an Item in a List
Java Program to Implement Sorted List
Python Program to Get the Full Path of the Current Working Directory
Spring Data JPA @Query
Spring Boot - Internationalization
Java Program to Implement Threaded Binary Tree
Java Program to Implement Multi-Threaded Version of Binary Search Tree
Hướng dẫn sử dụng Printing Service trong Java
Java Program to Implement Stein GCD Algorithm
Introduction to Spring MVC HandlerInterceptor
Tính kế thừa (Inheritance) trong java
Java Program to Solve the 0-1 Knapsack Problem
Java Program to Check if a Point d lies Inside or Outside a Circle Defined by Points a, b, c in a Pl...
Lập trình đa luồng trong Java (Java Multi-threading)
Quick Guide to java.lang.System
Documenting a Spring REST API Using OpenAPI 3.0
Multipart Upload with HttpClient 4
Encode/Decode to/from Base64
Java Program to Implement Iterative Deepening
Java Program to Describe the Representation of Graph using Adjacency Matrix
Composition, Aggregation, and Association in Java
REST Web service: Tạo ứng dụng Java RESTful Client với Jersey Client 2.x
Java Program to Find Whether a Path Exists Between 2 Given Nodes
Java – Convert File to InputStream
Java Program to Perform Right Rotation on a Binary Search Tree
Guide to WeakHashMap in Java
Java Program to Implement Double Order Traversal of a Binary Tree
How to Replace Many if Statements in Java
Introduction to Spring Data REST
Versioning a REST API