Skip to main content
https://badge.fury.io/py/Flask-Mail-SendGrid.svg

Flask extension for sendgrid. It has same interface with Flask-Mail.

Flask-Mail-SendGrid is friendly with another extention such as Flask-Security.

Installing Flask-Mail-SendGrid

Install with pypi:

$ pip install flask-mail-sendgrid

or install latest version:

$ git clone https://github.com/hamano/flask-mail-sendgrid.git
$ cd flask-mail-sendgrid
$ python setup.py install

Configuring Flask-Mail-SendGrid

  • MAIL_SENDGRID_API_KEY: API Key for SendGrid

  • MAIL_DEFAULT_SENDER: default sender

from flask import Flask
from flask_mail_sendgrid import MailSendGrid

app = Flask(__name__)
app.config['MAIL_SENDGRID_API_KEY'] = 'XXXXXXXX'
mail = MailSendGrid(app)

Sending messages

To send a message first create a Message instance:

from flask_mail import Message

@app.route("/")
def index():
    msg = Message("Hello",
                  sender="from@example.com",
                  recipients=["to@example.com"])

The message can contain a body and/or HTML:

msg.body = "testing"
msg.html = "<b>testing</b>"

Or, if you are using Templates in Sendgrid, you may specify a Template ID and Data:

msg.template_id = 'my-template-id'
msg.dynamic_template_data = {'first_name': 'John', 'last_name': 'Doe'}

Finally, to send the message, you use the Mail instance configured with your Flask application:

mail.send(msg)

Other options

msg = Message("Hello",
              sender="from@example.com",
              mail_options={'from_name': 'John'},
              recipients=["to@example.com"],
              cc=["to@example.com"],
              bcc=["to@example.com"])

Release files for Flask-Mail-SendGrid 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Mail-SendGrid 0.6
File Size Uploaded
Flask-Mail-SendGrid-0.6.tar.gz 3.2 kB Details

Release files / Flask-Mail-SendGrid-0.6.tar.gz

Download URL Flask-Mail-SendGrid-0.6.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7c34a3798f8677275e1faabf255d244d56eb1d249782abeef980d17eeedd0834
BLAKE2b-256 checksum
How to use checksums
8e6811e7ff237c5533c59dbd16b1d16001796d9709cbf0f7bb4986421e979e23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.6 This release

1 release file

0.5

1 release file

0.3

1 release file

0.2

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page