Forums

FlaskMail not sending mail

I've just tested my code on localhost and it's working perfectly. But I try the same thing on the website hosted here and it does not work. Same exact code. I'm using the Gmail SMTP servers. Is it blocked or something?

        try:
            mail.send(msg)
            flash("Your message has been received. We aim to reply back within a few hours","success")
        except:
            flash("An error occured. Try again", "error")

I'm getting the error message displayed which means that the message is not being sent for some reason

It's possible that Gmail are blocking access to your account from our servers; if you print out the exception that you're getting then it will appear in the server logs (accessible from the "Web" tab) and you should be able to confirm that.

If it does look like it's being blocked then check out the instructions under "Google security blocking and setting up an App-Specific password" on the using Gmail from PythonAnywhere help page

Seems that using the app specific password sorted out the problem. Thank you very much :)

Excellent! Glad to help :-)