gpt4 book ai didi

Java Mail - 电子邮件不通过 Gmail 发送

转载 作者:行者123 更新时间:2023-11-30 10:25:44 25 4
gpt4 key购买 nike

我正在尝试执行以下代码集,但无济于事。为此,我正在使用我的 Gmail 帐户。我已禁用两步验证并允许启用安全性较低的应用程序,但我一直收到错误消息:

javax.mail.AuthenticationFailedException: 534-5.7.14

public void sendEmail()
{
try
{
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");

Session session = Session.getInstance(props, new javax.mail.Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("example@gmail.com", "password");
}
});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("example@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("example@company.com"));
message.setSubject("Testing Subject");
message.setText("Testing Text");

Transport.send(message);

System.out.println("Mail Sent!");

}

catch (Exception ex)
{
ex.printStackTrace();
}
}

最佳答案

我需要做的就是启用两步验证,然后为应用程序生成一个应用程序密码。感谢大家的回应。 :)

关于Java Mail - 电子邮件不通过 Gmail 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46006443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com