Search code examples
flasksmtpgmailflask-mail

How to give access to Gmail for sending mail from flask?


I am building a flask application which sends a mail when the user clicks on submit in a form. I'm following this tutorial - https://www.geeksforgeeks.org/sending-emails-using-api-in-flask-mail/

However, when I tried to run the app, I got the following error : smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials 67-20020a620446000000b0056b9d9e2521sm2627179pfe.177 - gsmtp')

I understand that this is because google blocked my sign-in attempt? When I go to the link mentioned in the article to allow access, I got this - Allow apps to access settings image

Can I anyone help? Is there any workaround for this? How do I send an email from flask anymore?

What I tried : Everything on https://www.geeksforgeeks.org/sending-emails-using-api-in-flask-mail/ What I expected to happen : An email to be sent. What actually happened : Google seems to no longer allow third party sign-ins. So login attempt to send mail was blocked. Is there any other way to login/send mails from gmails in flask?


Solution

  • You can replace the password by "App Password", to create app password, you can read the page: https://support.google.com/mail/answer/185833?hl=en