Skip to content

hamano/flask-mail-sendgrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Mail-SendGrid

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="[email protected]",
                  recipients=["[email protected]"])

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="[email protected]",
              mail_options={'from_name': 'John'},
              recipients=["[email protected]"],
              cc=["[email protected]"],
              bcc=["[email protected]"])

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages