[英]Why javax.mail port changed from 2525 to 25
我使用山d发送邮件。 端口设置为2525
props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
//props.put("mail.smtp.**ssl.enable", "true");
//props.put("mail.smtp.**ssl.required", "true");
props.put("mail.smtp.host", settings.host);
props.put("mail.smtp.port", settings.port);
而且我确信所有设置都是有效的。
然后我设置身份验证器
authenticator = new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(settings.username, settings.password);
}
};
然后发送邮件
Session session = Session.getInstance(props, authenticator);
session.setDebug(true);
try {
Message message = mail.getMessage(session);
Transport.send(message);
System.out.println("Done");
return true;
} catch (MessagingException e) {
e.printStackTrace(System.err);
return false;
}
调试说我在25号端口上发送邮件
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.s
mtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.mandrillapp.com", port 25, isSSL fal
se
220 smtp.mandrillapp.com ESMTP
DEBUG SMTP: connected to host "smtp.mandrillapp.com", port: 25
我尝试创建“ smtps”传输,但这没有帮助。 Mandrill说我可以使用端口2525(或587等)。 我还使用具有相同凭据的Linux服务器上的后缀在端口2525上发送。
错误是很愚蠢的)
props.put("mail.smtp.port", settings.port);
在此行中,port是一个int
值,当我将port
字段更改为String
它开始工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.