參考:Java Mail: SSLHandshakeException when sending email on port 25 without SSL
需求:
最近一個小工具需使用到JAVAMAIL,奇怪的是我明明使用SMTP(非SSL)寄信,卻一直報SSL的錯誤:
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
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:275)
at javax.mail.Service.connect(Service.java:156)
查了半天才發現,只要關閉下列的Properties設定參數即可:
props.put("mail.smtp.starttls.enable", "true");
(把上一行取消就可)
沒有留言:
張貼留言