E-mail support for Flask applications

The ability to send e-mails is usually one of the most basic functions of any web application. It is usually easy to implement with any application. With Python-based applications, it is also quite simple to implement with the help of smtplib. In the case of Flask, this is further simplified by an extension called Flask-Mail.

Getting ready

Flask-Mail can be easily installed via pip:

$ pip install Flask-Mail

Let's take a simple case where en e-mail will be sent to a catalog manager in the application whenever a new category is added.

How to do it…

First, we need to instantiate the Mail object in our application's configuration, that is, my_app/__init__.py:

from flask_mail import Mail app.config['MAIL_SERVER'] = ...

Get Flask Framework Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.