java - Javamail Could not convert socket to TLS GMail -
i trying send email using javamail through gmails smtp server. code.
final string username = "mygmail@gmail.com"; final string password = "mygmailpassword"; properties props = new properties(); props.put("mail.smtp.auth", true); props.put("mail.smtp.starttls.enable", true); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); session session = session.getinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(username, password); } }); try { message message = new mimemessage(session); message.setfrom(new internetaddress("no-reply@gmail.com")); message.setrecipients(message.recipienttype.to, internetaddress.parse("test@gmail.com")); message.setsubject("testing subject"); message.settext("dear mail crawler," + "\n\n no spam email, please!"); transport.send(message); system.out.println("done"); } catch (messagingexception e) { throw new runtimeexception(e); }
returns error
could not convert socket tls;
the complete stacktrace
exception in thread "main" java.lang.runtimeexception: javax.mail.messagingexception: not convert socket tls; nested exception is: javax.net.ssl.sslhandshakeexception: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target @ test.main(test.java:43) caused by: javax.mail.messagingexception: not convert socket tls; nested exception is: javax.net.ssl.sslhandshakeexception: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target @ com.sun.mail.smtp.smtptransport.starttls(smtptransport.java:1907) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:666) @ javax.mail.service.connect(service.java:317) @ javax.mail.service.connect(service.java:176) @ javax.mail.service.connect(service.java:125) @ javax.mail.transport.send0(transport.java:194) @ javax.mail.transport.send(transport.java:124) @ test.main(test.java:38) caused by: javax.net.ssl.sslhandshakeexception: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target @ com.sun.net.ssl.internal.ssl.alerts.getsslexception(alerts.java:174) @ com.sun.net.ssl.internal.ssl.sslsocketimpl.fatal(sslsocketimpl.java:1649) @ com.sun.net.ssl.internal.ssl.handshaker.fatalse(handshaker.java:241) @ com.sun.net.ssl.internal.ssl.handshaker.fatalse(handshaker.java:235) @ com.sun.net.ssl.internal.ssl.clienthandshaker.servercertificate(clienthandshaker.java:1206) @ com.sun.net.ssl.internal.ssl.clienthandshaker.processmessage(clienthandshaker.java:136) @ com.sun.net.ssl.internal.ssl.handshaker.processloop(handshaker.java:593) @ com.sun.net.ssl.internal.ssl.handshaker.process_record(handshaker.java:529) @ com.sun.net.ssl.internal.ssl.sslsocketimpl.readrecord(sslsocketimpl.java:893) @ com.sun.net.ssl.internal.ssl.sslsocketimpl.performinitialhandshake(sslsocketimpl.java:1138) @ com.sun.net.ssl.internal.ssl.sslsocketimpl.starthandshake(sslsocketimpl.java:1165) @ com.sun.net.ssl.internal.ssl.sslsocketimpl.starthandshake(sslsocketimpl.java:1149) @ com.sun.mail.util.socketfetcher.configuresslsocket(socketfetcher.java:549) @ com.sun.mail.util.socketfetcher.starttls(socketfetcher.java:486) @ com.sun.mail.smtp.smtptransport.starttls(smtptransport.java:1902) ... 7 more caused by: sun.security.validator.validatorexception: pkix path building failed: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target @ sun.security.validator.pkixvalidator.dobuild(pkixvalidator.java:323) @ sun.security.validator.pkixvalidator.enginevalidate(pkixvalidator.java:217) @ sun.security.validator.validator.validate(validator.java:218) @ com.sun.net.ssl.internal.ssl.x509trustmanagerimpl.validate(x509trustmanagerimpl.java:126) @ com.sun.net.ssl.internal.ssl.x509trustmanagerimpl.checkservertrusted(x509trustmanagerimpl.java:209) @ com.sun.net.ssl.internal.ssl.x509trustmanagerimpl.checkservertrusted(x509trustmanagerimpl.java:249) @ com.sun.net.ssl.internal.ssl.clienthandshaker.servercertificate(clienthandshaker.java:1185) ... 17 more caused by: sun.security.provider.certpath.suncertpathbuilderexception: unable find valid certification path requested target @ sun.security.provider.certpath.suncertpathbuilder.enginebuild(suncertpathbuilder.java:174) @ java.security.cert.certpathbuilder.build(certpathbuilder.java:238) @ sun.security.validator.pkixvalidator.dobuild(pkixvalidator.java:318) ... 23 more
props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
Comments
Post a Comment