javamail SSL ÀÎÁõ¹æ½Ä »ç¿ë ½Ã javax.net.ssl.SSLHandshakeException 󸮹æ¹ý
from = ¡°adminaccount@gmail.com¡±;
Properties props = new Properties();
props.put(¡°mail.smtp.host¡±, ¡°smtp.gmail.com¡±);
props.setProperty(¡°mail.transport.protocol¡±, ¡°smtp¡±);
props.put(¡°mail.smtp.port¡±, ¡°465¡±);
props.put(¡°mail.smtp.starttls.enable¡±, ¡°true¡±);
props.put(¡°mail.debug¡±, ¡°true¡±);
props.put(¡°mail.smtp.auth¡±, ¡°true¡±);
props.put(¡°mail.smtp.socketFactory.class¡±, ¡°javax.net.ssl.SSLSocketFactory¡±);
props.put(¡°mail.smtp.socketFactory.fallback¡±, ¡°false¡±);
Authenticator auth = new MailAuthentication(¡°useraccount@gmail.com¡±, ¡°password¡±);
Session sess = Session.getDefaultInstance(props, auth);
ÀÌÇÏ »ý·«.
Could not connect to SMTP host: smtp.gmail.com, port: 465
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:1972)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at kr.or.dasan.user.comn.util.ComnUtil.sendMail(ComnUtil.java:242)
at kr.or.dasan.user.comn.MailThread.run(MailThread.java:42)
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 com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1584)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:848)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:877)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1089)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1116)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1100)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:548)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:352)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:207)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
¡¦ 8 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:221)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:145)
at sun.security.validator.Validator.validate(Validator.java:203)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:172)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(SSLContextImpl.java:320)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:841)
¡¦ 19 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:236)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:194)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:216)
¡¦ 24 more
ÀÌ·± ¿¡·¯°¡ ¶³¾îÁö¸é, ¾Æ·¡ ÷ºÎµÈ InstallCert.java¸¦ ÄÄÆÄÀÏ ÇÑ´Ù.
> java InstallCert smtp.gmail.com:465 ¸¦ ½ÇÇàÇϸé
¹¹°¡ ÂÒ¸£¸¤ ½ÇÇàµÇ¸é¼ Enter certificate to add to trusted keystore or ¡®q¡¯ to quit: [1] ¸Þ¼¼Áö°¡ ¶ß¸é Enter.
jssecacerts ¶ó´Â ÆÄÀÏÀÌ »ý¼ºÀÌ µÇ´Âµ¥ JAVA_HOME/jre/lib/security/·Î ¿Å°ÜµÐ´Ù.
±×¸®°í ¼¹ö restart¸¦ ÇÏ¸é ¸ÞÀÏ Àü¼Û ¼º°ø