All Projects → sklarsa → Django Sendgrid V5

sklarsa / Django Sendgrid V5

Licence: mit
An implementation of Django's EmailBackend compatible with sendgrid-python v5+

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Sendgrid V5

Django Anymail
Django email backends and webhooks for Amazon SES, Mailgun, Mailjet, Postmark, SendGrid, Sendinblue, SparkPost and more
Stars: ✭ 1,109 (+449.01%)
Mutual labels:  django, sendgrid
Django Behaviors
Easily integrate common behaviors for Django models, e.g. Timestamps, Publishing, Authoring, Editing and more.
Stars: ✭ 201 (-0.5%)
Mutual labels:  django
Django Sspanel
用diango开发的shadowsocks/V2ray面板
Stars: ✭ 2,538 (+1156.44%)
Mutual labels:  django
Vecihi
Build Your Own Photo Sharing App in 5 minutes
Stars: ✭ 199 (-1.49%)
Mutual labels:  django
Django Bootstrap3
Bootstrap 3 integration with Django.
Stars: ✭ 2,271 (+1024.26%)
Mutual labels:  django
Okuna Api
🤖 The Okuna Social Network API
Stars: ✭ 200 (-0.99%)
Mutual labels:  django
Rengorum
🚀 Forum app built in React, Redux & Django
Stars: ✭ 194 (-3.96%)
Mutual labels:  django
Djangochannelsgraphqlws
Django Channels based WebSocket GraphQL server with Graphene-like subscriptions
Stars: ✭ 203 (+0.5%)
Mutual labels:  django
Django Oms
加强版运维系统,集成工单、发布、监控、管理dns、saltstack
Stars: ✭ 201 (-0.5%)
Mutual labels:  django
My blog
My Django Blog
Stars: ✭ 198 (-1.98%)
Mutual labels:  django
Django Job Portal
Job portal application using Django
Stars: ✭ 196 (-2.97%)
Mutual labels:  django
Django Webpack Loader
Transparently use webpack with django
Stars: ✭ 2,327 (+1051.98%)
Mutual labels:  django
42 corrections
Corrections files of 42 School
Stars: ✭ 198 (-1.98%)
Mutual labels:  django
Repoll
Redis管理平台Repoll,现已开源,基于redis3.x,支持单机、哨兵以及集群模式
Stars: ✭ 196 (-2.97%)
Mutual labels:  django
Django Material
Material Design for Django
Stars: ✭ 2,362 (+1069.31%)
Mutual labels:  django
Django Rest Auth
This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
Stars: ✭ 2,289 (+1033.17%)
Mutual labels:  django
Django Secretballot
🗳 django voting application that allows semi-anonymous voting
Stars: ✭ 197 (-2.48%)
Mutual labels:  django
Django Rest Marshmallow
Marshmallow schemas for Django REST framework
Stars: ✭ 198 (-1.98%)
Mutual labels:  django
Django Graphql Auth
Django registration and authentication with GraphQL.
Stars: ✭ 200 (-0.99%)
Mutual labels:  django
Django Maintenance Mode
shows a 503 error page when maintenance-mode is on. 🚧 🛠
Stars: ✭ 200 (-0.99%)
Mutual labels:  django

django-sendgrid-v5

Latest Release

This package implements an email backend for Django that relies on sendgrid's REST API for message delivery.

It is under active development, and pull requests are more than welcome!

To use the backend, simply install the package (using pip), set the EMAIL_BACKEND setting in Django, and add a SENDGRID_API_KEY key (set to the appropriate value) to your Django settings.

How to Install

  1. pip install django-sendgrid-v5
  2. In your project's settings.py script:
    1. Set EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
    2. Set the SENDGRID_API_KEY in settings.py to your api key that was provided to you by sendgrid. SENDGRID_API_KEY = os.environ["SENDGRID_API_KEY"]

Other settings

  1. To toggle sandbox mode (when django is running in DEBUG mode), set SENDGRID_SANDBOX_MODE_IN_DEBUG = True/False.
    1. To err on the side of caution, this defaults to True, so emails sent in DEBUG mode will not be delivered, unless this setting is explicitly set to False.
  2. SENDGRID_ECHO_TO_STDOUT will echo to stdout or any other file-like object that is passed to the backend via the stream kwarg.
  3. SENDGRID_TRACK_EMAIL_OPENS - defaults to true and tracks email open events via the Sendgrid service. These events are logged in the Statistics UI, Email Activity interface, and are reported by the Event Webhook.
  4. SENDGRID_TRACK_CLICKS_HTML - defaults to true and, if enabled in your Sendgrid account, will tracks click events on links found in the HTML message sent.
  5. SENDGRID_TRACK_CLICKS_PLAIN - defaults to true and, if enabled in your Sendgrid account, will tracks click events on links found in the plain text message sent.

Usage

Simple

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

Dynamic Template with JSON Data

First, create a dynamic template and copy the ID.

from django.core.mail import EmailMessage

msg = EmailMessage(
  from_email='[email protected]',
  to=['[email protected]'],
)
msg.template_id = "your-dynamic-template-id"
msg.dynamic_template_data = {
  "title": foo
}
msg.send(fail_silently=False)

The kitchen sink EmailMessage (all of the supported sendgrid-specific properties)

from django.core.mail import EmailMessage

msg = EmailMessage(
  from_email='[email protected]',
  to=['[email protected]'],
  cc=['[email protected]'],
  bcc=['[email protected]'],
)

# Personalization custom args
# https://sendgrid.com/docs/for-developers/sending-email/personalizations/
msg.custom_args = {'arg1': 'value1', 'arg2': 'value2'}

# Reply to email address (sendgrid only supports 1 reply-to email address)
msg.reply_to = '[email protected]'

# Send at (accepts an integer per the sendgrid docs)
# https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html#-Send-At
msg.send_at = 1600188812

# Transactional templates
# https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/
msg.template_id = "your-dynamic-template-id"
msg.dynamic_template_data = {  # Sendgrid v6+ only
  "title": foo
}
msg.substitutions = {
  "title": bar
}

# Unsubscribe groups
# https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/
msg.asm = {'group_id': 123, 'groups_to_display': ['group1', 'group2']}

# Categories
# https://sendgrid.com/docs/glossary/categories/
msg.categories = ['category1', 'category2']

# IP Pools
# https://sendgrid.com/docs/ui/account-and-settings/ip-pools/
msg.ip_pool_name = 'my-ip-pool'


msg.send(fail_silently=False)

Examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].