java - Could not connect to SMTP host -
i trying send email via our private smtp server here code
public static void main(string args[]) throws messagingexception { properties props = system.getproperties(); props.put("mail.smtps.host", "gi-systems.net"); props.put("mail.smtps.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.port", "25"); session session = session.getinstance(props, null); message msg = new mimemessage(session); msg.setfrom(new internetaddress("xxxx@gi-systems.net")); msg.setrecipients(message.recipienttype.to, internetaddress.parse("yyyy@hotmail.com, false)); msg.setsubject("password recovery"); msg.settext(pwd); msg.setsentdate(new date()); smtptransport t = (smtptransport) session.gettransport("smtps"); t.connect("smtp.gi-systems.net", "xxxx@gi-systems.net", "mypassword"); t.sendmessage(msg, msg.getallrecipients()); system.out.println("response: " + t.getlastserverresponse()); t.close(); }
but when run code got exception
exception in thread "main" javax.mail.messagingexception: not connect smtp host: smtp.gi-systems.net, port: 465; 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.openserver(smtptransport.java:1706) @ com.sun.mail.smtp.smtptransport.protocolconnect(smtptransport.java:525) @ javax.mail.service.connect(service.java:291) @ javax.mail.service.connect(service.java:172) @ com.mycompany.sendmail.app.sendemail(app.java:45) @ com.mycompany.sendmail.app.main(app.java:64) 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 @ sun.security.ssl.alerts.getsslexception(alerts.java:192) @ sun.security.ssl.sslsocketimpl.fatal(sslsocketimpl.java:1886) ......
ps: when use gmail smtp , email address works fine
how can fix exception???
check following things:
for example gmail.
1.
t.connect("smtp.gmail.com", "mailid", "password");
2.properties:
props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); //for gmail 'smtp.gmail.com' check yours props.put("mail.smtp.port","587");//or port 465
please check case.
it seems wrong setting properties or authentication.
Comments
Post a Comment