Link to home
Start Free TrialLog in
Avatar of Jagdeep Singh
Jagdeep Singh

asked on

Can't send command to SMTP host

Unable to send an emailjavax.mail.MessagingException: Can't send command to SMTP host;
  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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

It's possible that the SMTP server is using a certificate that's defective/unrecognized. You need to tell that admins of that host about the problem
Avatar of Jagdeep Singh
Jagdeep Singh

ASKER

I am using gmail mail server. I download the certificate and import into jre. But still facing the same issue.
Yes, By this example, I am able to send mail.
But did not understand why I am facing the issue of certification with my code on the windows while the same code is working on Linux.
That's odd. Please post full stack trace of exception on Windows
Sending...
The email was not sent.
javax.mail.MessagingException: Can't send command to SMTP host;
  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
Error message: Can't send command to SMTP host
      at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1420)
      at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1408)
      at com.sun.mail.smtp.SMTPTransport.ehlo(SMTPTransport.java:847)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:384)
      at javax.mail.Service.connect(Service.java:297)
      at javax.mail.Service.connect(Service.java:156)
      at javax.mail.Service.connect(Service.java:105)
      at javax.mail.Transport.send0(Transport.java:168)
      at javax.mail.Transport.send(Transport.java:98)
      at com.amazon.mail.AmazonSESSample.main(AmazonSESSample.java:108)
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(Alerts.java:192)
      at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
      at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
      at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
      at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514)
      at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
      at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
      at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
      at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
      at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
      at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:747)
      at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:123)
      at com.sun.mail.util.TraceOutputStream.write(TraceOutputStream.java:101)
      at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
      at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
      at com.sun.mail.smtp.SMTPTransport.sendCommand(SMTPTransport.java:1418)
      ... 9 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(PKIXValidator.java:387)
      at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
      at sun.security.validator.Validator.validate(Validator.java:260)
      at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
      at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
      at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
      at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1496)
      ... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
      at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
      at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
      at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
      at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
      ... 26 more
Is the clock set correctly with a time server on the Windows box?
Best to start at the beginning...

1) Provide the recipient's domain part of their email address, like... gmail.com or yahoo.com

2) Provide the port your submitting on - 25, 587, some other port

3) Say whether you're using a user/pass to authenticate or using unauthenticated submission

4) Based on your stack trace it appears you're Java is trying to connect to some external site to submit mail + using bad CA data.

This makes very little sense.

First, use http://www.jetmore.org/john/code/swaks/ to test your connection.

Once you have a working SWAKS invocation, then port settings you use to Java... Here's an example...

swaks -s smtp.mailgun.org:587 -tls -auth -au relay@mailgun.foo.com -ap 62UvhB9sJsx2VfnyuVW0d2ohsakNKM21 --from=me@foo.com --to=someone@someotherfoo.com

Open in new window

Thanks for your reply.

Yes, time is correct.
You're not by any chance using a proxy server are you?

4) Based on your stack trace it appears you're Java is trying to connect to some external site to submit mail + using bad CA data.
smtp.gmail.com i suppose
No proxy,
Now my code is working, I have to install the cert.

Thank you for your support :)
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.