smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted)
Since You can't use the less secure app now as the deadline was 30th May 2022.
An alternative way to send Gmail via flask using an App password
Before generating the APP password your google account must enable the 2FA.
If the 2FA is enabled then you can hop on to the security section in the manage accounts and there you can see the APP password section.
For generating the APP password you also can read -> here
The below code I tried and it's working
I have used python another dependencies
pip install Flask-Mail
from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
mail= Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'someone@gmail.com'
app.config['MAIL_PASSWORD'] = 'YOUR_APP_PASSWORD'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
@app.route("/")
def index():
msg = Message('Hello', sender = 'someone@gmail.com', recipients = ['someone@gmail.com'])
msg.body = "Hello Flask message sent from Flask-Mail"
mail.send(msg)
return "Sent"
if __name__ == '__main__':
app.run(debug = True)
Login Authentication failed with Gmail SMTP (Updated)
Google has disabled the ability to enable less secure apps as of May 2022. Because of this, the previous solution of enabling less secure apps is no longer valid.
Steps:
- Go into your sending email address and make your way to the settings.
- Find two-step authentication and enable it.
- Under two-step authentication there should be a tab labeled App passwords. Click on it then select mail as the app and your device of choice
- Use the password generated from the app password as the password for your Gmail account.
Credits to: Link to source
Nodemailer: response: '535-5.7.8 Username and Password not accepted
Solved it by creating App password inside Google account. You must have 2-step verification actived.
Related Topics
Set Markers for Individual Points on a Line in Matplotlib
Pandas Group by and Find First Non Null Value for All Columns
How to Access Function Variables in Another Function
How to Use Groupby to Concatenate Strings in Python Pandas
Rename Specific Column(S) in Pandas
What Version of Visual Studio Is Python on My Computer Compiled With
Shuffle an Array with Python, Randomize Array Item Order with Python
Functions That Help to Understand JSON(Dict) Structure
Python's JSON Module, Converts Int Dictionary Keys to Strings
Why Does My Pandas Dataframe Not Display New Order Using 'Sort_Values'
Call a Python Function from Jinja2
How to Get 2.X-Like Sorting Behaviour in Python 3.X
Accessing Attributes on Literals Work on All Types, But Not 'Int'; Why
How to Randomly Choose a Maths Operator and Ask Recurring Maths Questions with It
Python - Difference Between Two Strings
Accessing Attributes on Literals Work on All Types, But Not 'Int'; Why