我正在创建一个向用户发送邮件的应用程序。
但问题是当我使用 Transport.send(msg) 方法时,它显示以下错误:
com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required.
我使用以下属性发送邮件。
props.put("mail.transport.protocol", "smtp");
props.put("mail.host", smtpHostName);
props.put("mail.user", smtpUser);
props.put("mail.password", smtpPass);
props.put("mail.smtp.auth", smtpAuth == 1 ? true : false);
props.put("mail.port", smtpPort);
props.put("mail.smtp.starttls.enable", smtpTLS == 1 ? true : false);
请帮助我解决此问题。
试试这个
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "false");
props.put("mail.smtp.port", port);
创建会话时使用此身份验证代码
l_session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
l_session.setDebug(true);
我们的环境在 WebSphere 7 下运行。要支持安全的 smtps,打开 SMTP 身份验证的正确变体是:
"mail.smtps.auth=true"
实际上,根据反编译源,在授权邮件会话之前,WebSphere 会检查是否存在由"mail"组成的属性。+ 传输协议 + ".auth" 设置为"true"。这有助于我通过gmail发送电子邮件。