Forums

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"] = 'stmp.gmail.com'
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', myadress@gmail.com')
app.config["MAIL_MAX_EMAILS"] = None
app.config["MAIL_ASCII_ATTACHMENTS"] = False
mail = Mail(app)

@app.route('/ontest')
def ontest():

    msg = Message("yo", recipients = ["…@....fr"])
    msg.body = "hi"
    mail.send(msg)

    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 smtp.gmail.com, not stmp.gmail.com.

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 https://support.google.com/mail/?p=BadCredentials z3sm2178504qkj.40 - gsmtp')"

Maybe i could try with something else than smtp.gmail?

That sounds simply like you're using the wrong username or password; the username should be your full email address (that is, something like "something@gmail.com", 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 :-)