org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465


Samebug tips2

If you're using wiremock, configure your code to accept wiremock self-signed certificate or create a keystore and certificate that are trusted by your HTTP client and configure wiremock to use that


7 months ago
Expert tip

Set the mail.smtp.ssl.trust system property to an smtp host, like smtp.gmail.com.


,
via Stack Overflow by carlos

Solutions on the web149

Solution icon of github
via GitHub by benwhicks
, 5 months ago
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of stackoverflow
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
via GitHub by oolso
, 1 year ago
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
via GitHub by arturek1666
, 10 months ago
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of stackoverflow
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of web
via ksup.org by Unknown author, 1 year ago
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
via GitHub by jmrichardson
, 1 year ago
Sending the email to the following server failed : smtp.gmail.com:465

Solution icon of github
Sending the email to the following server failed : smtp.gmail.com:465

Stack trace

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:465
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1410)
	at org.apache.commons.mail.Email.send(Email.java:1437)
	at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at RJavaTools.invokeMethod(RJavaTools.java:386)
Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
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.smtp.SMTPTransport.openServer(SMTPTransport.java:2055)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
	at javax.mail.Service.connect(Service.java:386)
	at javax.mail.Service.connect(Service.java:245)
	at javax.mail.Service.connect(Service.java:194)
	at javax.mail.Transport.send0(Transport.java:253)
	at javax.mail.Transport.send(Transport.java:124)
	at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1400)
	... 5 more
Caused by: 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 sun.security.ssl.Alerts.getSSLException(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
	at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
	at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
	at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
	at sun.security.ssl.Handshaker.processLoop(Unknown Source)
	at sun.security.ssl.Handshaker.process_record(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
	at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:348)
	at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:215)
	at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2019)
	... 12 more
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
	at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
	at sun.security.validator.Validator.validate(Unknown Source)
	at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
	at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
	at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
	... 24 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
	at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
	at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
	at java.security.cert.CertPathBuilder.build(Unknown Source)
	... 30 more

Write tip

You have a different solution? A short tip here would help you and many other users who saw this issue last week.

Users with the same issue

Samebug visitor profile picture
Unknown user
Once, 3 months ago
Samebug visitor profile picture
Unknown user
Once, 1 year ago
Samebug visitor profile picture
Unknown user
Once, 1 year ago
Samebug visitor profile picture
Unknown user
2 times, 1 year ago
Samebug visitor profile picture
Unknown user
Once, 1 year ago
58 more bugmates