javax.mail.AuthenticationFailedException: 535-5.7.8 用户名和密码不被接受
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35347269/
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
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
提问by Rohit Raj
I am getting this error when I try to send mail using the JavaMail API:
当我尝试使用 JavaMail API 发送邮件时出现此错误:
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted
How can I fix this?
我怎样才能解决这个问题?
回答by Mathews Mathai
You probably got this error because the username and password of the from mail id is not matching. Please recheck your password and mail-id (username). It could be a typo.
您收到此错误可能是因为来自邮件 ID 的用户名和密码不匹配。请重新检查您的密码和邮件 ID(用户名)。这可能是一个错字。
In some cases, Gmail prevents logging in through external applications or programs which are not authorised. Also login to your gmail account to check if gmail has prevented logging in to your account via your Java Mail API program.
在某些情况下,Gmail 会阻止通过未经授权的外部应用程序或程序登录。同时登录到您的 gmail 帐户以检查 gmail 是否阻止通过您的 Java Mail API 程序登录到您的帐户。
If nothing works, you could try some other SMTP server (like yahoo, yandex).
如果没有任何效果,您可以尝试其他一些 SMTP 服务器(如 yahoo、yandex)。
回答by ThinkTank
Sorry for coming late to Party.These could be the problem in your task if you are using Gmail Server.
很抱歉来晚了。如果您使用 Gmail 服务器,这些可能是您任务中的问题。
- Two Step Verification should be turned off.
- Allow Less Secure App(should be turned on).
- Please Check Your UserName and Password.
- Check the code(which was my Problem), Above three You can change form google help center and by Yourself last one My Experience I can Share with You. You need to Authenticate the Mail server before Communicating the message because it is Challenge Response System By which You are Communicating through the mail.I am sharing code snippets file youcan refer not able to format my code by ctrl+K.
- 应该关闭两步验证。
- 允许不太安全的应用程序(应打开)。
- 请检查您的用户名和密码。
- 检查代码(这是我的问题),以上三个您可以更改形式谷歌帮助中心和自己最后一个我可以与您分享的经验。您需要在通信消息之前对邮件服务器进行身份验证,因为它是您通过邮件进行通信的质询响应系统。我正在共享代码片段文件,您可以参考无法通过 ctrl+K 格式化我的代码。
回答by user3769960
- First of all make sure that all properties should be defined as follows:-
- 首先确保所有属性都应定义如下:-
mail.smtp.host=smtp.gmail.com
,
mail.smtp.port=25
,
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp.host=smtp.gmail.com
,
mail.smtp.port=25
,
mail.smtp.auth=true
mail.smtp.starttls.enable=true
Now,make sure that two step verification is off
Allow less secure app (ON) follow this link :-
现在,确保两步验证关闭
允许安全性较低的应用程序 (ON) 跟随此链接:-
https://myaccount.google.com/lesssecureapps
https://myaccount.google.com/lesssecureapps
- Also, check your username and password is correct or not.
- 另外,请检查您的用户名和密码是否正确。
回答by KP Developer
Follow the steps:
按照步骤:
- Disable antivirus
- Allow Less Secure App On
- Two Step Verification should be turned off.
- 禁用防病毒软件
- 允许不太安全的应用程序
- 应该关闭两步验证。
回答by tarun kumar143
1.Allow Less Secure App(should be turned on).
1.允许不太安全的应用程序(应该打开)。
2.Check Gmail Username and Password..
2.检查Gmail用户名和密码..
public static void main(String[] args) {
final String username = "YourMailId";
final String password = "password";
Properties prop = new Properties();
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "587");
prop.put("mail.smtp.auth", "true");
prop.put("mail.smtp.starttls.enable", "true"); //TLS
Session session = Session.getInstance(prop,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(
Message.RecipientType.TO,
InternetAddress.parse("[email protected], [email protected]")
);
message.setSubject("Testing Gmail TLS");
message.setText("Dear Mail Crawler,"
+ "\n\n Please do not spam my email!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
回答by Nguy?n D??ng
Log on gmail account, in Account ->
登录gmail帐户,在帐户->
click Security -> turn off 2-step verification and turn on "Less secure app access"
单击“安全”->“关闭两步验证”并打开“不太安全的应用程序访问”
May be because of things above, hope help you
可能是因为上面的事情,希望能帮到你
回答by ognjenkl
This worked for me:
这对我有用:
- Login to the gmail account you are sending mail from
- Go to Manage your Google Account -> Security -> Less secure app access -> Turn on access (not recommended)
or
Access the URL:
https://www.google.com/settings/security/lesssecureapps - Turn "Allow less secure apps: OFF" to "Allow less secure apps: ON"
- 登录到您发送邮件的 Gmail 帐户
- 转到管理您的 Google 帐户 -> 安全性 -> 不太安全的应用程序访问 -> 打开访问权限(不推荐)
或
访问 URL:https:
//www.google.com/settings/security/lesssecureapps - 将“允许安全性较低的应用程序:关闭”改为“允许安全性较低的应用程序:开启”
回答by Y.LAGHOUAZI
It works for me, you must configure your Gmail account with the below steps:
它对我有用,您必须按照以下步骤配置您的 Gmail 帐户:
In the security section:
在安全部分:
You need to Change "Allow less secure apps: OFF" to "Allow less secure apps: ON"
您需要将“允许安全性较低的应用程序:关闭”更改为“允许安全性较低的应用程序:开启”
回答by Chaklader Asfak Arefe
I have the same error but when I run the app from the terminal, it goes away. My email configuration is provided:
我有同样的错误,但是当我从终端运行应用程序时,它消失了。提供了我的电子邮件配置:
spring.mail.host=smtp.googlemail.com
[email protected]
spring.mail.password=Weddingcard.1
spring.mail.port=587
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.required=true