发送SMTP电子邮件时发生AuthenticationFailedException错误 [英] AuthenticationFailedException error while sending SMTP email
本文介绍了发送SMTP电子邮件时发生AuthenticationFailedException错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在java中发送SMTP电子邮件,但我有这样的错误,我没有收到邮件。
我关闭所有防火墙和防病毒软件。
I try to send SMTP email in java, but I have an error like this and I don't get a mail. I turn off all firewall and anti-virus.
错误:
javax.mail.AuthenticationFailedException: 534-5.7.14<https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuIW
534-5.7.14 tAxHxbq4WR-vUuV1uOFAvx8NhInfxYTyNHi_8sJ80lX5lBdBla2ROiSKoysMNcFoQ6sGe
534-5.7.14 DUh173tDMolJ64W-Rahx1fhVF_08AvWrphibgQXiyyz5U1FNMMb-eGGJlUIbjyvBgQuZY6
534-5.7.14 tnykIXdVn__mg87aOmtxoss-EiFYeKdvuiBbt5eb9t_NOc97h-PkXOco-9FcYW69Iz9CTu
534-5.7.14 rfyhlo24k9oqIiWtcJwv85oUCO2g> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 pd8sm1306363pdb.93 - gsmtp
这是我的代码:
private void btn_mailActionPerformed(java.awt.event.ActionEvent evt) {
String to = "receive.address@gmail.com";
String from = "send.address@gmail.com";
final String username = "send.address";
final String password = "sendpassword";
String host = "smtp.gmail.com";
Properties pro = new Properties();
pro.put("mail.smtp.host",host);
pro.put("mail.smtp.socketFactory.port","465");
pro.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
pro.put("mail.smtp.auth","true");
pro.put("mail.smtp.port","465");
Session session = Session.getInstance(pro,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username,password);
}
}
);
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject("test mail");
message.setText("Hello how are you?");
Transport.send(message);
JOptionPane.showMessageDialog(null,"Send");
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,e.toString());
System.out.println(e.toString());
}
推荐答案
从浏览器登录电子邮件和转到此页。你会看到这个;
Login to email from browser and go this page. You will see this;
请务必点击开启并再次尝试使用您的代码。
Make sure to click "Turn on" and try your code again.
这篇关于发送SMTP电子邮件时发生AuthenticationFailedException错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文