Sending a mail from Flask-Mail (SMTPSenderRefused 530) Sending a mail from Flask-Mail (SMTPSenderRefused 530) flask flask

Sending a mail from Flask-Mail (SMTPSenderRefused 530)


While digging into the issues faced, I rechecked the SMTP settings for Google,

Google SMTP settings

Changing the

app.config['MAIL_SERVER'] = 'smtp.googlemail.com'

to

app.config['MAIL_SERVER'] = 'smtp.gmail.com'

did the trick.

Also make sure that the full username is used as Gmail SMTP username, i.e., example@gmail.com as shown in the image above.

Hope this helps!!!


You need to change your Google account settings. On this page, turn on the option to "Allow less secure apps".

As that page says:

Some apps and devices use less secure sign-in technology, which makes your account more vulnerable. You can turn off access for these apps, which we recommend, or turn on access if you want to use them despite the risks. Learn more


I also followed this book and get the same problem, after some digging here and there, I found out the root cause of the problem. However, I am not sure whether it will be the same case for you or not.

app.config['MAIL_USERNAME'] = os.environ.get('MAIL_USERNAME')app.config['MAIL_PASSWORD'] = os.environ.get('MAIL_PASSWORD')

As you can see your flask app gets the your email credentials through os.environ.get(), and if you set this environment variables temporarily in your system, in my case Mac OSX, after your terminal session they will be gone, so you need to set them again for the next time you enter the terminal, like below:

export MAIL_USERNAME=**YOUR EMAIL**export PASSWORD=**YOUR PASSWORD**

I got this error because of this scenario, in order to set them permanently you need to include these variables into .bash_profile file in your home directory.