send mail

The objective of my website is to send email and it doesn’t work. I don’t really understand why, and I have already bought a paying account.

from flask_mail import Mail, Message
app.config["MAIL_SERVER"] = ''
app.config["MAIL_USE_TLS"] = True
app.config["MAIL_USE_SSL"] = False
app.config["MAIL_USERNAME"] = 'me'
app.config["MAIL_PASSWORD"] = mypassword
app.config["MAIL_DEBUG"] = True
app.config["MAIL_SUPPRESS_SEND"] = False
app.config["MAIL_PORT"] = 587
app.config["MAIL_DEFAULT_SENDER"] = ('me',')
app.config["MAIL_MAX_EMAILS"] = None
app.config["MAIL_ASCII_ATTACHMENTS"] = False
mail = Mail(app)

def ontest():

    msg = Message("yo", recipients = ["…"])
    msg.body = "hi"

    return "Message sent!"

Then I get : Internal Server Error

Is there somebody who can help me? Thanks a lot!

I have the same problem with my website. Please need help

What are you getting in your error logs?

P.S. connecting to Google's servers should be fine on a free account...they whitelist it

@Prcha @freyfrancois You may need to enable Gmail App-Specific Password

@ tylerhand : thank you! they say a lot of thing but at the end, they wrote :

socket.gaierror: [Errno -2] Name or service not known

@fjl : i tried it today but it didn't work

There's a typo in your MAIL_SERVER setting -- it should be, not

Giles, thank you for this. It's one of my mistake but it's steel not working.

"Paramètre "Autoriser les applications moins sécurisées" activé" which mean folowin google trad : "Authorization of less secure applications" parameter activated

Yes, this is a Google Account setting that you will need to change. You can read more about it here.

@Prcha what errors do you see in your error logs?

with access secure app i tried "disable" then "enable" then "disable", then "enable" and i always get :

"smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 z3sm2178504qkj.40 - gsmtp')"

Maybe i could try with something else than

That sounds simply like you're using the wrong username or password; the username should be your full email address (that is, something like "", not just "something").

We also recommend that you use app-specific passwords; that's a different thing to "less secure apps", and normally works fine.

It works ! Thanks you all of you! Thank you Giles!

Excellent! Glad we could help :-)