A simple example on how to use flask-mail with google or google apps email accounts. Other sources:
-Flask-mail docs: http://packages.python.org/flask-mail/
-Google support: http://support.google.com/mail/bin/answer.py?hl=en&answer=78799
@kfk
from flask import Flask
from flaskext.mail import Mail, Message
app =Flask(__name__)
mail=Mail(app)
app.config.update(
DEBUG=True,
#EMAIL SETTINGS
MAIL_SERVER='smtp.gmail.com',
MAIL_PORT=465,
MAIL_USE_SSL=True,
MAIL_USERNAME = 'you@google.com',
MAIL_PASSWORD = 'GooglePasswordHere'
)
mail=Mail(app)
@app.route("/")
def index():
msg = Message(
'Hello',
sender='you@dgoogle.com',
recipients=
['recipient@recipient_domain.com'])
msg.body = "This is the email body"
mail.send(msg)
return "Sent"
if __name__ == "__main__":
app.run()
This snippet by kfk can be used freely for anything you like. Consider it public domain.
Comments
Getting Google App account working by Andrew Kaiser on 2012-06-20 @ 19:26
I struggled getting a Google Apps account to work with Flask-Mail. These are the settings that eventually worked for me. Figured this might help someone else.
app.config.update( DEBUG=True,
I'm brand new to Flask/Python and I was just wondering if someone could explain why it didn't appear that the mail settings I'd make in my config.py file would take. The config settings for SQLAlchemy work fine from the config.py file, but for some reason these mail settings won't work.