Flask extension for sendgrid. It has same interface with Flask-Mail.
Project description
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",
mail_options={'from_name': 'John'},
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-Mail-SendGrid-0.5.tar.gz
.
File metadata
- Download URL: Flask-Mail-SendGrid-0.5.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa2d9e749dbc40886de69d5498c4a6f60f3118e913832e863c993a3aca4818b |
|
MD5 | cdbfe94248160278353ba74e1a622525 |
|
BLAKE2b-256 | af8435b38d673b305f6934d3b2134c35200e7c1db07545504f5d9c5fe62d873a |