• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

(Simple Java Mail) ... unable to find valid certification path to requested target

 
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!  (Beginner java)   using "Simple Java Mail" jar

I think something is looking for a security certificate (my computer's OS, Netbeans IDE, Gmail server ... I dont know  :  (

I am getting this third party error:

Exception in thread "AWT-EventQueue-0" org.simplejavamail.mailer.internal.mailsender.MailSenderException: Third party error
at org.simplejavamail.mailer.internal.mailsender.MailSender.sendMailClosure(MailSender.java:222)
at org.simplejavamail.mailer.internal.mailsender.MailSender.send(MailSender.java:172)
at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:332)
at org.simplejavamail.mailer.Mailer.sendMail(Mailer.java:323)
at myNewSMDR.MainDisplay.jButton4ActionPerformed(MainDisplay.java:529)
at myNewSMDR.MainDisplay.access$200(MainDisplay.java:30)
at myNewSMDR.MainDisplay$4.actionPerformed(MainDisplay.java:171)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS;
 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.startTLS(SMTPTransport.java:2064)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:724)
at javax.mail.Service.connect(Service.java:388)
at javax.mail.Service.connect(Service.java:246)
at javax.mail.Service.connect(Service.java:195)
at org.simplejavamail.mailer.internal.mailsender.MailSender.sendMailClosure(MailSender.java:204)





 
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if this is your problem or not, but you should probably be using port 465 for TLS rather than 587.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
suppose the SSL certificate isn't trusted by Java.

Just add below code to trust the certificate

http://stackoverflow.com/questions/33868167/javax-net-ssl-sslhandshakeexception-sun-security-validator-validatorexception
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.... (Java beginner here)   I see the code your referring to .... what do I do with it? Whats that code do?  

PS: I tried all the other port numbers as well ..... but get same error.
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running the "X509TrustManager()"  code  before my Email code .... etting same error.
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

...... this is what i'm running now ...... same error!


 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can send mail through Gmail (and others) by either connecting using SMTPS on port 465, or by connecting using SMTP on port 576 and then upgrading with STARTTLS - both will work.

All you need to send email from your Java application is JavaMail.  If you search around, you can find lots of half-working examples, so I've included some basic working code to help with understanding how to use the API.

SMTPS
SMTP + STARTTLS
Test Driver
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I been try different mail code all night .... and get that same error.  I'll try what you sent now.  Thank-you for helping! :  )
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

SMTP + STARTTLS  ver.
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
..... same for other ver.

DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=Rick, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 smtp.gmail.com ESMTP 24sm15936358qtx.8 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587

EHLO 192.168.1.100
250-smtp.gmail.com at your service, [50.78.128.54]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
Exception in thread "main" javax.mail.MessagingException: Could not convert socket to TLS;
 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
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DEBUG: setDebug: JavaMail version 1.5.6
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: protocolConnect returning false, host=smtp.gmail.com, user=Rick, password=<null>
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false
220 smtp.gmail.com ESMTP c142sm754231qkb.10 - gsmtp
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587

EHLO 192.168.1.100
250-smtp.gmail.com at your service, [50.78.128.54]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250 SMTPUTF8
DEBUG SMTP: Found extension "SIZE", arg "35882577"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SMTPUTF8", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
Exception in thread "main" javax.mail.MessagingException: Could not convert socket to TLS;
 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
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The solution to this issue can be found unter "Other Topics" in the Security FAQ.
 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rick Liberato wrote: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

SMTP + STARTTLS  ver.


Seems like your certs are not up to date.


What OS and version are you using, and which version of the JRE?

I am running Java 1.8.0_121-b13 on Centos 6 and 1.8.0_45-b15 on Windows 10 - code works fine on both.
 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have firewall/anti-virus software (comodo, Avast, etc.) on your workstation which might be messing with secure connections?
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XP Pro 2002 Ser Pac 3   JDK 1.8.0_121
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are "certs" and how do ya update'em :  )
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what the link I posted explains.
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shut down AVG email scan ..... NOW ALL IS WORKING!!!

......  YOUR THE BOMMER!!!  Thank-you!!!  :  )
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.... I assume there is a way I can tell AVG to NOT look at my app's E-mail sending? (an exception to all others)
 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rick Liberato wrote:XP Pro 2002 Ser Pac 3   JDK 1.8.0_121


Hmm - that's quite old, and I know there are issues with XP supporting current SHA256-signed certificates.

I do have a laptop with XP somewhere at the office - I'll try it tomorrow and see if I run in to the same problem.

Edit: Just saw you last response so I won't need to dust off the old laptop.
 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rick Liberato wrote:.... I assume there is a way I can tell AVG to NOT look at my app's E-mail sending? (an exception to all others)


I am using Avast on my Windows desktop and I have it configuired to not intercept and scan SSL traffic.  I've never had it enabled, so I don't know if that would cause this type of problem for me if it was on.

I've never used AVG, so no advise on what you can do with that.
 
Rick Liberato
Ranch Hand
Posts: 104
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WOW! .... this was a hard lesson! (Shut-off email scanners when coding Email apps!)  :  (  This problem beat me up all night.
Thank-you again for your expertise in this!
 
Ron McLeod
Sheriff
Posts: 4644
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rick Liberato wrote:WOW! .... this was a hard lesson! (Shut-off email scanners when coding Email apps!)  :  (  This problem beat me up all night.
Thank-you again for your expertise in this!


Have a cow as reward for not giving up.  
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic