Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hamano/flask-mail-sendgrid
Flask extension for sendgrid. It has same interface with Flask-Mail.
https://github.com/hamano/flask-mail-sendgrid
Last synced: about 1 month ago
JSON representation
Flask extension for sendgrid. It has same interface with Flask-Mail.
- Host: GitHub
- URL: https://github.com/hamano/flask-mail-sendgrid
- Owner: hamano
- Created: 2018-04-09T12:19:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-19T16:06:59.000Z (over 1 year ago)
- Last Synced: 2024-10-31T23:46:48.913Z (about 2 months ago)
- Language: Python
- Homepage: https://pypi.org/project/Flask-Mail-SendGrid/
- Size: 23.4 KB
- Stars: 16
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
- awesome-flask - Flask-Mail-SendGrid - Provides simple email base on Flask-Mail for sending email by SendGrid. (Third-Party Extensions / Email)
README
Flask-Mail-SendGrid
===================.. image:: https://badge.fury.io/py/Flask-Mail-SendGrid.svg
:target: https://badge.fury.io/py/Flask-Mail-SendGridFlask 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:
.. code:: bash
$ pip install flask-mail-sendgrid
or install latest version:
.. code:: bash
$ git clone https://github.com/hamano/flask-mail-sendgrid.git
$ cd flask-mail-sendgrid
$ python setup.py installConfiguring Flask-Mail-SendGrid
-------------------------------- MAIL\_SENDGRID\_API\_KEY: API Key for SendGrid
- MAIL\_DEFAULT\_SENDER: default sender.. code:: python
from flask import Flask
from flask_mail_sendgrid import MailSendGridapp = Flask(__name__)
app.config['MAIL_SENDGRID_API_KEY'] = 'XXXXXXXX'
mail = MailSendGrid(app)Sending messages
----------------To send a message first create a Message instance:
.. code:: python
from flask_mail import Message
@app.route("/")
def index():
msg = Message("Hello",
sender="[email protected]",
recipients=["[email protected]"])The message can contain a body and/or HTML:
.. code:: python
msg.body = "testing"
msg.html = "testing"Or, if you are using Templates in Sendgrid, you may specify a Template ID and Data:
.. code:: python
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:.. code:: python
mail.send(msg)
Other options
.. code:: python
msg = Message("Hello",
sender="[email protected]",
mail_options={'from_name': 'John'},
recipients=["[email protected]"],
cc=["[email protected]"],
bcc=["[email protected]"])