Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A Django email backend for the SendGrid API

Project description

A Django email backend for the SendGrid API

https://travis-ci.org/jtstio/django-sgapi.svg?branch=master

Installation

Install the backend from PyPI:

pip install django-sgapi

Add the following to your project’s settings.py:

EMAIL_BACKEND = "sgbackend.SendGridBackend"
SENDGRID_API_KEY = "Your SendGrid API Key"

Done!

Example

from django.core.mail import send_mail
from django.core.mail import EmailMultiAlternatives

# Send a simple message
send_mail('Hello there!', 'Emails are the future!',
  'Jay Hale <jay@jtst.io>', ['hello@sink.sendgrid.net'])

# Send a more complex message
mail = EmailMultiAlternatives(
  subject='Hello there again!',
  body='Who knew you could do so many things with email?!?',
  from_email='Jay Hale <jay@jtst.io>',
  to=['hello@sink.sendgrid.net'],
)
mail.reply_to = 'No Reply <no-reply@sink.sendgrid.net>'
mail.template_id = 'marketing_template_5'
mail.substitutions = {'%organization%': 'jtstio'}
with open('flyer.pdf', 'rb') as file:
    mail.attachments = [
        ('flyer.pdf', file.read(), 'application/pdf')
    ]
mail.attach_alternative(
    "<p>Who knew you could do <strong>so many things</strong> with email?!?</p>",
    "text/html"
)
mail.send()

Attribution

sendgrid-django-v5: An alternative implementation you should check out

sendgrid-django: Basis for this implementation

sendgrid-python: Python SendGrid connector

License

MIT

Enjoy :)

Project details


Release history Release notifications

This version
History Node

2.0.0

History Node

1.0.0

History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-sgapi-2.0.0.tar.gz (4.3 kB) Copy SHA256 hash SHA256 Source None Oct 16, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page