Reputation: 221
I am having trouble sending an email from my gmail account with my java application.
I have written simple Java code to send emails from my application. I have MFA turned on and I have created an App Password and I am using it in my code. When I execute the code I get the message
javax.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials ft13-20020a17090b0f8d00b0022630ba1c80sm1576429pjb.42 - gsmtp
I am fairly certain that the error message is not related to a code issue (but what do I know?) and I have double checked the credentials multiple times to ensure they are correct. I'm trying to understand what else could be the issue. I'd appreciate any advice or things to check.
Upvotes: 22
Views: 45648
Reputation: 61
Please follow the below steps
Hope this helps ....
Upvotes: 6
Reputation: 21854
Edit January 2024:
Beginning September 30, 2024, Google Workspace will no longer support the sign-in method for third-party apps or devices that require users to share their Google username and password (the "Less secure app access" option).
OAuth and App Passwords will still work tho.
Announcement: https://workspaceupdates.googleblog.com/2023/09/winding-down-google-sync-and-less-secure-apps-support.html
Original answer:
Not sure if it's because my account is part of Google Workplace, but as of November 2023, I still have access to the "Less secure app access" option:
As the message says in the image, Google will eventually automatically turn it off and the message "535-5.7.8 Username and Password not accepted" will appear when trying to log in with SMTP.
The process to reenable it is as simple as:
To not forget about it, I log the process into stdout when I catch the exception in my app:
with SMTP(SMTP_CONN_STRING) as smtp:
try:
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
smtp.login(SMTP_USERNAME, SMTP_PASSWORD)
except SMTPAuthenticationError as e:
logging.info(str(e))
logging.info(
"⚠️ Google automatically turned off the security option to log in"
" with a username and a password."
)
logging.info(
"⚠️ To enable it again: Log in to the Google account >"
" Manage your Google account > Security > Less secure app access > Turn in on"
)
Upvotes: 3
Reputation: 117016
Username and Password not accepted
Is the standard error message when you are trying to connect to Googles SMPT server and are trying to use the users actual google password.
As of May 30 2022 google has removed the less secure apps option. There is no way to turn this on as it no longer exists.
You have two options
Quick fix for SMTP username and password not accepted error
Upvotes: 17