Home > Java > javaTutorial > How to use both SSL and non-SSL connections in Java Mail?

How to use both SSL and non-SSL connections in Java Mail?

王林
Release: 2023-04-27 14:31:07
forward
1717 people have browsed it

Recently, I encountered a problem when doing java mail ssl: using JavaMail to receive emails cannot succeed after the system has been running for a certain period of time.
The error message is as follows:
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service. java:156)
at javax.mail.Service.connect(Service.java:105)
Or the mail server that does not enable SSL has the following error:
nested exception is:
java.net.ConnectException : Connection refused
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:148)

Telnet to the mail server, the username and password are OK. It seems that there is only a program problem.

Properties props = System.getProperties() was used when creating MailSession; when I printed this out, I found an error. SSL verification should not have been used, but the verification information should not have appeared, so now If you do not need an SSL link every time you connect to POP3, remove these attributes and the problem will be gone.
Finally I know who changed System.getProperties(); It turns out that there is another system running in the same Tomcat. The mail server used by that system uses SSL verification to send and receive emails, and will receive emails once every 30 minutes. Because the program was not written rigorously enough, the above errors occurred. After improving the program, the two systems could finally coexist in one TOMCAT.

The above is the detailed content of How to use both SSL and non-SSL connections in Java Mail?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template