Forums

Sending email from python app

Hello! I have a problem during sending letters from app to email. I use flask_mail with such settings: Either

app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '***@gmail.com'
app.config['MAIL_PASSWORD'] = '***'
mail = Mail(app)

or

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

have no results. On local machine both of these ways works. What am I doing wrong?

Google is probably rejecting your request because you have not authenticated the PythonAnywhere server. Look in your error logs to confim. We have a help page for dealing with this: http://help.pythonanywhere.com/pages/SMTPForFreeUsers/

Thanks. How can I authentificate my PythonAnywhere server for reject such problems in future? P.S. I try to use yandex's smtp servers (as I understand, yandex is in whitelist of pythonanywhere) and nothing changes.

Follow the instructions I posted previously.

I don't know why yandex would not work for you.

Thanx. I solved it. Yandex SMTP works well))

Maybe it will be useful for others: I used this settings:

app.config['MAIL_SERVER'] = 'smtp.yandex.ru'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'username' # only login without @yandex.ru
app.config['MAIL_PASSWORD'] = 'password'

Thanks for posting that :-)