Snippets are unofficial and unmaintained.
This is an archived view of user-submitted snippets. Despite being hosted on the Flask site, they are not official. No Flask maintainer has curated or checked the snippets for security, correctness, or design.
TurboMail is an email package originally bundled with TurboGears but now existing as a standalone library.
It provides convenient functionality for configuring and sending emails, for example for testing, multipart messages, etc.
It's quite straightforward to set up TurboMail for your Flask application. One thing you need to take care of is ensuring that the interface is set up so that when the current process exits, any unsent emails are cleanly dispatched. This is achieved using the standard atexit module.
import atexit
from turbomail.control import interface
from turbomail.message import Message
from flask import Flask
# pass in dict of config options
interface.start({'mail.on' : True})
# ensures interface cleanly shutdown when process exits
atexit.register(interface.stop, force=True)
app = Flask(__name__)
@app.route("/")
def index():
# send an email
msg = Message("from@example.com",
"to@example.com",
"a subject")
msg.plain = "body of message"
msg.send()
This snippet by Dan Jacob can be used freely for anything you like. Consider it public domain.
Comments
HTML messages by Dag Odenhall on 2010-05-14 @ 10:41
You can render HTML messages from templates.
Plain text from templates by Dag Odenhall on 2010-05-14 @ 10:46
Nothing stops you from rendering the plain text messages from templates too, of course.
Marrow.mailer by Priit Laes on 2011-11-09 @ 13:09
TurboMail project has now changed its name to marrow.mailer.