A Django email backend for the SendGrid API
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 :)
Release files for django-sgapi 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-sgapi-2.0.0.tar.gz | 4.3 kB | Details |
Release files / django-sgapi-2.0.0.tar.gz
| Download URL | django-sgapi-2.0.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f37918857de3e53a190aab5fe6cc80f1aefb57d0baa5c94f39267fd485335b0
|
|
BLAKE2b-256 checksum How to use checksums |
b36e8cb59f968a0f117163d3c61b8bd806c56c3f13379610068302334f5904d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |