[英]Could not connect to SMTP host: smtp8.net4india.com, port: 25;
While sent email showing error: 在发送显示错误的电子邮件时:
javax.mail.MessagingException: Could not connect to SMTP host: smtp8.net4india.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
My email settings is: 我的电子邮件设置是:
String mailProcessed = "";
Properties props = new Properties();
props.put("mail.smtp.host", "smtp8.net4india.com");
props.put("mail.smtp.socketFactory.port", "25");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable", "true");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(frmMail, frmPass);
}
});
remove props.put("mail.smtp.starttls.enable", "true");
删除
props.put("mail.smtp.starttls.enable", "true");
and add props.put("mail.smtp.ssl.enable", "true");
并添加
props.put("mail.smtp.ssl.enable", "true");
You are using SSL, not TLS. 您正在使用SSL,而不是TLS。
Also make sure the mail server supports SSL. 还要确保邮件服务器支持SSL。
Also make sure that the mail server is using TCP protocol SMTP
, they might be using IMAP
or POP3
. 还要确保邮件服务器正在使用TCP协议
SMTP
,它们可能正在使用IMAP
或POP3
。 In that case you need to change the properties you reference by the protocol they use, ie: props.put("mail.pop3.socketFactory.port", "25");
在这种情况下,您需要通过使用的协议来更改引用的属性,即:
props.put("mail.pop3.socketFactory.port", "25");
props.put("mail.pop3.socketFactory.class","javax.net.ssl.SSLSocketFactory");
You are using getDefaultInstance
for the session, but if a session was already established it will return the existing session and your properties will be lost. 您正在为会话使用
getDefaultInstance
,但是如果已经建立了会话,它将返回现有会话,并且您的属性将丢失。
Check the common mistakes page, it has it all: https://javaee.github.io/javamail/FAQ#commonmistakes 检查常见错误页面,它具有全部内容: https : //javaee.github.io/javamail/FAQ#commonmistakes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.