JavaMail异常javax.mail.AuthenticationFailedException 534-5.7.9需要特定于应用程序的密码
我想用JavaMailAPI发送邮件 我已经做了一些编码,但它不工作抛出异常:- 消息发送失败javax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码JavaMail异常javax.mail.AuthenticationFailedException 534-5.7.9需要特定于应用程序的密码,java,email,jakarta-mail,Java,Email,Jakarta Mail,我想用JavaMailAPI发送邮件 我已经做了一些编码,但它不工作抛出异常:- 消息发送失败javax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码 package com.appreciationcard.service; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import
package com.appreciationcard.service;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.appreciationcard.dao.DAOFactory;
import com.appreciationcard.forms.ComposeForm;
public class MailServiceImpl implements MailService {
public boolean mailsent(ComposeForm composeForm) {
String to = composeForm.getTo();
String from = composeForm.getFrom();
String cc = composeForm.getCc();
String bcc = composeForm.getBcc();
String subject = composeForm.getSubject();
String messages = composeForm.getMessage();
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.port", "587");
props.put("mail.transport.protocol", "smtp");
props.put("mail.debug", "true");
System.out.println("Properties" + props);
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"tosudhansusekhar@gmail.com", "xxxx");
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress("dynamicmihir@gmail.com"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
to));
message.setSubject(subject);
message.setText(messages);
Transport.send(message);
} catch (MessagingException mex) {
System.out.println("Message Sending Failed" + mex);
mex.printStackTrace();
}
}
}
我在服务器控制台上遇到异常
消息发送失败javax.mail.AuthenticationFailedException:534-5.7.9需要特定于应用程序的密码
了解更多信息,请访问534 5.7.9 o5sm11464195pdr.50-gsmtp
请任何人帮我解决这个问题。错误消息和知识库文章似乎非常正确:您需要使用谷歌邮件服务器的应用程序密码。您可以在google的帐户页面上创建这些一次性密码。您可能试图通过启用了双因素身份验证的gmail帐户发送邮件。继续操作时,需要将6位身份验证令牌作为SMS消息发送到您的移动设备,或通过Google Authenticator应用程序生成。或者,您可以通过谷歌基于web的ui生成特定于应用程序的密码,并在通过java代码访问邮件帐户时使用该密码。您问题中的将引导您完成整个过程。您已为您的Google帐户启用,因此应用程序将无法使用实际密码登录到您的Google帐户。Google希望您为您使用的每个应用程序生成一个特定于应用程序的密码(并给它一个名称),然后使用该密码从您的应用程序登录到您的Google帐户。这允许您在启用两步身份验证时不将密码提供给第三方应用程序 另一种方法是,您的应用程序支持重定向到Google页面,以使用Google Authenticator应用程序生成的用户名、密码和代码进行身份验证
这清楚地说明了该做什么。只需为您的帐户创建一个应用程序密码并使用该密码即可 创建密码的步骤: 转到您的帐户设置()-->>安全-->>在登录到谷歌-->>应用程序密码-->>下输入您的凭据以登录您的帐户-->>选择“应用程序”和“设备”->>生成 将密码复制并粘贴到某处
您可以使用此密码而不是您的帐户密码。请澄清,您是否按照链接中的说明生成了特定于应用程序的密码?i、 例如,即使使用特定于应用程序的密码,您是否也会出现错误?您是否阅读了该页面?在某些系统上,上面列出的有用URL的链接会被屏蔽。这就是我为什么来到这里的原因——因此,在这方面,这仍然是一个很有帮助的问题。非常感谢您提供的宝贵信息。我的问题解决了,邮件发送成功。感谢Saket先生的快速回复。谢谢!从上一个小时开始就一直在找这个!!