gmailgmail-apiflask-mail

how to send an email with flask-mail from a bussiness acount?


I`m trying to send mails with flask-mail, which I achieved since anaccount@gmail.com, but in production we need to send the mail from anaccount@myowndomain.mx which fails because from "@gmail.com" i can permit less secure apps, but in bussiness gmail acount I can´t...so my question is... ¿Is there another way to permite less secure apps? or ¿How coul I do my app more secure?, a workaround? thanks in advance.

here´s my flask-mail configuration.

from flask_mail import Mail, Message 

app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '@myowndomain.mx'
app.config['MAIL_PASSWORD'] = '**********'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)

Solution

  • I solved the problem in base of this: https://www.twilio.com/blog/2018/03/send-email-programmatically-with-gmail-python-and-flask.html

    first you have to create a two step verification to your gmail account, then create an app password, and use this app pasword in the flask-mail configuration