Jagdeep Singh
asked on
Can't send command to SMTP host
Unable to send an emailjavax.mail.MessagingE xception: Can't send command to SMTP host;
nested exception is:
javax.net.ssl.SSLHandshake Exception: sun.security.validator.Val idatorExce ption: PKIX path building failed: sun.security.provider.cert path.SunCe rtPathBuil derExcepti on: unable to find valid certification path to requested target
nested exception is:
javax.net.ssl.SSLHandshake
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
ASKER
I am using gmail mail server. I download the certificate and import into jre. But still facing the same issue.
You shouldn't need to import a cert for Google. See
http://technojeeves.com/index.php/aliasjava1/44-send-secure-mail-via-google-with-java
http://technojeeves.com/index.php/aliasjava1/44-send-secure-mail-via-google-with-java
ASKER
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.
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
ASKER
Sending...
The email was not sent.
javax.mail.MessagingExcept ion: Can't send command to SMTP host;
nested exception is:
javax.net.ssl.SSLHandshake Exception: sun.security.validator.Val idatorExce ption: PKIX path building failed: sun.security.provider.cert path.SunCe rtPathBuil derExcepti on: unable to find valid certification path to requested target
Error message: Can't send command to SMTP host
at com.sun.mail.smtp.SMTPTran sport.send Command(SM TPTranspor t.java:142 0)
at com.sun.mail.smtp.SMTPTran sport.send Command(SM TPTranspor t.java:140 8)
at com.sun.mail.smtp.SMTPTran sport.ehlo (SMTPTrans port.java: 847)
at com.sun.mail.smtp.SMTPTran sport.prot ocolConnec t(SMTPTran sport.java :384)
at javax.mail.Service.connect (Service.j ava:297)
at javax.mail.Service.connect (Service.j ava:156)
at javax.mail.Service.connect (Service.j ava:105)
at javax.mail.Transport.send0 (Transport .java:168)
at javax.mail.Transport.send( Transport. java:98)
at com.amazon.mail.AmazonSESS ample.main (AmazonSES Sample.jav a:108)
Caused by: javax.net.ssl.SSLHandshake Exception: sun.security.validator.Val idatorExce ption: PKIX path building failed: sun.security.provider.cert path.SunCe rtPathBuil derExcepti on: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.ge tSSLExcept ion(Alerts .java:192)
at sun.security.ssl.SSLSocket Impl.fatal (SSLSocket Impl.java: 1949)
at sun.security.ssl.Handshake r.fatalSE( Handshaker .java:302)
at sun.security.ssl.Handshake r.fatalSE( Handshaker .java:296)
at sun.security.ssl.ClientHan dshaker.se rverCertif icate(Clie ntHandshak er.java:15 14)
at sun.security.ssl.ClientHan dshaker.pr ocessMessa ge(ClientH andshaker. java:216)
at sun.security.ssl.Handshake r.processL oop(Handsh aker.java: 1026)
at sun.security.ssl.Handshake r.process_ record(Han dshaker.ja va:961)
at sun.security.ssl.SSLSocket Impl.readR ecord(SSLS ocketImpl. java:1062)
at sun.security.ssl.SSLSocket Impl.perfo rmInitialH andshake(S SLSocketIm pl.java:13 75)
at sun.security.ssl.SSLSocket Impl.write Record(SSL SocketImpl .java:747)
at sun.security.ssl.AppOutput Stream.wri te(AppOutp utStream.j ava:123)
at com.sun.mail.util.TraceOut putStream. write(Trac eOutputStr eam.java:1 01)
at java.io.BufferedOutputStre am.flushBu ffer(Buffe redOutputS tream.java :82)
at java.io.BufferedOutputStre am.flush(B ufferedOut putStream. java:140)
at com.sun.mail.smtp.SMTPTran sport.send Command(SM TPTranspor t.java:141 8)
... 9 more
Caused by: sun.security.validator.Val idatorExce ption: PKIX path building failed: sun.security.provider.cert path.SunCe rtPathBuil derExcepti on: unable to find valid certification path to requested target
at sun.security.validator.PKI XValidator .doBuild(P KIXValidat or.java:38 7)
at sun.security.validator.PKI XValidator .engineVal idate(PKIX Validator. java:292)
at sun.security.validator.Val idator.val idate(Vali dator.java :260)
at sun.security.ssl.X509Trust ManagerImp l.validate (X509Trust ManagerImp l.java:324 )
at sun.security.ssl.X509Trust ManagerImp l.checkTru sted(X509T rustManage rImpl.java :229)
at sun.security.ssl.X509Trust ManagerImp l.checkSer verTrusted (X509Trust ManagerImp l.java:124 )
at sun.security.ssl.ClientHan dshaker.se rverCertif icate(Clie ntHandshak er.java:14 96)
... 20 more
Caused by: sun.security.provider.cert path.SunCe rtPathBuil derExcepti on: unable to find valid certification path to requested target
at sun.security.provider.cert path.SunCe rtPathBuil der.build( SunCertPat hBuilder.j ava:141)
at sun.security.provider.cert path.SunCe rtPathBuil der.engine Build(SunC ertPathBui lder.java: 126)
at java.security.cert.CertPat hBuilder.b uild(CertP athBuilder .java:280)
at sun.security.validator.PKI XValidator .doBuild(P KIXValidat or.java:38 2)
... 26 more
The email was not sent.
javax.mail.MessagingExcept
nested exception is:
javax.net.ssl.SSLHandshake
Error message: Can't send command to SMTP host
at com.sun.mail.smtp.SMTPTran
at com.sun.mail.smtp.SMTPTran
at com.sun.mail.smtp.SMTPTran
at com.sun.mail.smtp.SMTPTran
at javax.mail.Service.connect
at javax.mail.Service.connect
at javax.mail.Service.connect
at javax.mail.Transport.send0
at javax.mail.Transport.send(
at com.amazon.mail.AmazonSESS
Caused by: javax.net.ssl.SSLHandshake
at sun.security.ssl.Alerts.ge
at sun.security.ssl.SSLSocket
at sun.security.ssl.Handshake
at sun.security.ssl.Handshake
at sun.security.ssl.ClientHan
at sun.security.ssl.ClientHan
at sun.security.ssl.Handshake
at sun.security.ssl.Handshake
at sun.security.ssl.SSLSocket
at sun.security.ssl.SSLSocket
at sun.security.ssl.SSLSocket
at sun.security.ssl.AppOutput
at com.sun.mail.util.TraceOut
at java.io.BufferedOutputStre
at java.io.BufferedOutputStre
at com.sun.mail.smtp.SMTPTran
... 9 more
Caused by: sun.security.validator.Val
at sun.security.validator.PKI
at sun.security.validator.PKI
at sun.security.validator.Val
at sun.security.ssl.X509Trust
at sun.security.ssl.X509Trust
at sun.security.ssl.X509Trust
at sun.security.ssl.ClientHan
... 20 more
Caused by: sun.security.provider.cert
at sun.security.provider.cert
at sun.security.provider.cert
at java.security.cert.CertPat
at sun.security.validator.PKI
... 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/joh n/code/swa ks/ to test your connection.
Once you have a working SWAKS invocation, then port settings you use to Java... Here's an example...
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/joh
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
ASKER
Thanks for your reply.
Yes, time is correct.
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
ASKER
No proxy,
Now my code is working, I have to install the cert.
Thank you for your support :)
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 TRIALMembers 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.