java java中如何解决com.sun.mail.smtp.SMTPSendFailedException?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11189320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to solve com.sun.mail.smtp.SMTPSendFailedException in java ?
提问by Babu R
I am creating a application in which i am sending mail to users.
我正在创建一个应用程序,在其中向用户发送邮件。
But the problem is while i am using Transport.send(msg) method, it displays the following error:
但问题是当我使用 Transport.send(msg) 方法时,它显示以下错误:
com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required.
I am using the following properties to send mail.
我正在使用以下属性发送邮件。
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);
Please help me to resolve this problem.
请帮我解决这个问题。
回答by Rahul Agrawal
Try this
试试这个
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "false");
props.put("mail.smtp.port", port);
And while creating session use this authentication code
在创建会话时使用此身份验证代码
l_session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
l_session.setDebug(true);
回答by Alex
Our environment is running under WebSphere 7. To support secured smtps, correct variant to turn on SMTPS AUTHorization is:
我们的环境在 WebSphere 7 下运行。为了支持安全的 smtps,打开 SMTPS AUTHorization 的正确变体是:
"mail.smtps.auth=true"
“mail.smtp s.auth=true”
Actually, according to decompiled sources, before authorizing the mail session WebSphere checks if there is a property composed as: "mail."+ transportProtocol + ".auth" set to "true". This helped me to send emails via gmail.
实际上,根据反编译的来源,在授权邮件会话之前,WebSphere 会检查是否有一个属性组成为:“mail.”+ transportProtocol + “.auth” 设置为“true”。这帮助我通过 gmail 发送电子邮件。