django-sendgrid-v5


Namedjango-sendgrid-v5 JSON
Version 1.2.2 PyPI version JSON
download
home_pagehttps://github.com/sklarsa/django-sendgrid-v5
SummaryAn implementation of Django's EmailBackend compatible with sendgrid-python v5+
upload_time2022-12-22 20:41:28
maintainer
docs_urlNone
authorSteven Sklar
requires_python
licenseMIT
keywords django email sendgrid backend
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-sendgrid-v5

[![Latest Release](https://img.shields.io/pypi/v/django-sendgrid-v5.svg)](https://pypi.python.org/pypi/django-sendgrid-v5/)

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

```python
from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    'from@example.com',
    ['to@example.com'],
    fail_silently=False,
)
```

### Dynamic Template with JSON Data

First, create a [dynamic template](https://mc.sendgrid.com/dynamic-templates) and copy the ID.

```python
from django.core.mail import EmailMessage

msg = EmailMessage(
  from_email='to@example.com',
  to=['to@example.com'],
)
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)

```python
from django.core.mail import EmailMessage

msg = EmailMessage(
  from_email='to@example.com',
  to=['to@example.com'],
  cc=['cc@example.com'],
  bcc=['bcc@example.com'],
)

# 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 = 'reply-to@example.com'

# Send at (accepts an integer per the sendgrid docs)
# https://docs.sendgrid.com/for-developers/sending-email/scheduling-parameters#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)
```


### FAQ
**How to change a Sender's Name ?**


`from_email="John Smith <john.smith@example.org>"`
You can just include the name in the from_email field of the _```EmailMessage```_ class 

```
msg = EmailMessage(
  from_email='Sender Name <from@example.com>',
  to=['to@example.com'],
)
```

**How to make mails to multiple users private (hide all the email addresses to which the mail is sent) to each person (personalization) ?**


Setting the `make_private` attribute to `True` will help us achieve it
```
msg = EmailMessage(
  from_email='Sender Name <from@example.com>',
  to=['to@example.com','abc@example.com','xyz@example.com'],
)
msg.make_private = True
```

## Examples

- Marcelo Canina [(@marcanuy)](https://github.com/marcanuy) wrote a great article demonstrating how to integrate `django-sendgrid-v5` into your Django application on his site: [https://simpleit.rocks/python/django/adding-email-to-django-the-easiest-way/](https://simpleit.rocks/python/django/adding-email-to-django-the-easiest-way/)
- RX-36 [(@DevWoody856)](https://github.com/DevWoody856) demonstrates how to use `django-sendgrid-v5` to make a contact form for your web application: https://rx-36.life/post/create-a-contact-form-using-sendgrid-in-django/


## Stargazers over time

[![Stargazers over time](https://starchart.cc/sklarsa/django-sendgrid-v5.svg)](https://starchart.cc/sklarsa/django-sendgrid-v5)




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sklarsa/django-sendgrid-v5",
    "name": "django-sendgrid-v5",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django email sendgrid backend",
    "author": "Steven Sklar",
    "author_email": "sklarsa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4a/51/a371b8816e55b289139311b85b9c51e81dd344b99c46761820b582e837a6/django-sendgrid-v5-1.2.2.tar.gz",
    "platform": null,
    "description": "# django-sendgrid-v5\n\n[![Latest Release](https://img.shields.io/pypi/v/django-sendgrid-v5.svg)](https://pypi.python.org/pypi/django-sendgrid-v5/)\n\nThis package implements an email backend for Django that relies on sendgrid's REST API for message delivery.\n\nIt is under active development, and pull requests are more than welcome\\!\n\nTo 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.\n\n## How to Install\n\n1. `pip install django-sendgrid-v5`\n2. In your project's settings.py script:\n    1. Set `EMAIL_BACKEND = \"sendgrid_backend.SendgridBackend\"`\n    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\"]`\n\n### Other settings\n\n1. To toggle sandbox mode (when django is running in DEBUG mode), set `SENDGRID_SANDBOX_MODE_IN_DEBUG = True/False`.\n    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.\n2. `SENDGRID_ECHO_TO_STDOUT` will echo to stdout or any other file-like\n    object that is passed to the backend via the `stream` kwarg.\n3. `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.\n4. `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.\n5. `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.\n\n## Usage\n\n### Simple\n\n```python\nfrom django.core.mail import send_mail\n\nsend_mail(\n    'Subject here',\n    'Here is the message.',\n    'from@example.com',\n    ['to@example.com'],\n    fail_silently=False,\n)\n```\n\n### Dynamic Template with JSON Data\n\nFirst, create a [dynamic template](https://mc.sendgrid.com/dynamic-templates) and copy the ID.\n\n```python\nfrom django.core.mail import EmailMessage\n\nmsg = EmailMessage(\n  from_email='to@example.com',\n  to=['to@example.com'],\n)\nmsg.template_id = \"your-dynamic-template-id\"\nmsg.dynamic_template_data = {\n  \"title\": foo\n}\nmsg.send(fail_silently=False)\n```\n\n### The kitchen sink EmailMessage (all of the supported sendgrid-specific properties)\n\n```python\nfrom django.core.mail import EmailMessage\n\nmsg = EmailMessage(\n  from_email='to@example.com',\n  to=['to@example.com'],\n  cc=['cc@example.com'],\n  bcc=['bcc@example.com'],\n)\n\n# Personalization custom args\n# https://sendgrid.com/docs/for-developers/sending-email/personalizations/\nmsg.custom_args = {'arg1': 'value1', 'arg2': 'value2'}\n\n# Reply to email address (sendgrid only supports 1 reply-to email address)\nmsg.reply_to = 'reply-to@example.com'\n\n# Send at (accepts an integer per the sendgrid docs)\n# https://docs.sendgrid.com/for-developers/sending-email/scheduling-parameters#send-at\nmsg.send_at = 1600188812\n\n# Transactional templates\n# https://sendgrid.com/docs/ui/sending-email/how-to-send-an-email-with-dynamic-transactional-templates/\nmsg.template_id = \"your-dynamic-template-id\"\nmsg.dynamic_template_data = {  # Sendgrid v6+ only\n  \"title\": foo\n}\nmsg.substitutions = {\n  \"title\": bar\n}\n\n# Unsubscribe groups\n# https://sendgrid.com/docs/ui/sending-email/unsubscribe-groups/\nmsg.asm = {'group_id': 123, 'groups_to_display': ['group1', 'group2']}\n\n# Categories\n# https://sendgrid.com/docs/glossary/categories/\nmsg.categories = ['category1', 'category2']\n\n# IP Pools\n# https://sendgrid.com/docs/ui/account-and-settings/ip-pools/\nmsg.ip_pool_name = 'my-ip-pool'\n\n\nmsg.send(fail_silently=False)\n```\n\n\n### FAQ\n**How to change a Sender's Name ?**\n\n\n`from_email=\"John Smith <john.smith@example.org>\"`\nYou can just include the name in the from_email field of the _```EmailMessage```_ class \n\n```\nmsg = EmailMessage(\n  from_email='Sender Name <from@example.com>',\n  to=['to@example.com'],\n)\n```\n\n**How to make mails to multiple users private (hide all the email addresses to which the mail is sent) to each person (personalization) ?**\n\n\nSetting the `make_private` attribute to `True` will help us achieve it\n```\nmsg = EmailMessage(\n  from_email='Sender Name <from@example.com>',\n  to=['to@example.com','abc@example.com','xyz@example.com'],\n)\nmsg.make_private = True\n```\n\n## Examples\n\n- Marcelo Canina [(@marcanuy)](https://github.com/marcanuy) wrote a great article demonstrating how to integrate `django-sendgrid-v5` into your Django application on his site: [https://simpleit.rocks/python/django/adding-email-to-django-the-easiest-way/](https://simpleit.rocks/python/django/adding-email-to-django-the-easiest-way/)\n- RX-36 [(@DevWoody856)](https://github.com/DevWoody856) demonstrates how to use `django-sendgrid-v5` to make a contact form for your web application: https://rx-36.life/post/create-a-contact-form-using-sendgrid-in-django/\n\n\n## Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/sklarsa/django-sendgrid-v5.svg)](https://starchart.cc/sklarsa/django-sendgrid-v5)\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An implementation of Django's EmailBackend compatible with sendgrid-python v5+",
    "version": "1.2.2",
    "split_keywords": [
        "django",
        "email",
        "sendgrid",
        "backend"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a5254177c4d2316cbd440d2cffaab0a8",
                "sha256": "fc55d0116e696850d8133c20239d2f5b6fb155193389aa56559c4410da53b63a"
            },
            "downloads": -1,
            "filename": "django_sendgrid_v5-1.2.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5254177c4d2316cbd440d2cffaab0a8",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 11043,
            "upload_time": "2022-12-22T20:41:26",
            "upload_time_iso_8601": "2022-12-22T20:41:26.641022Z",
            "url": "https://files.pythonhosted.org/packages/58/05/2fc1e2d555141b8297f3b3ba8d438af714b34bc4c71cd81dd36bf038ec7e/django_sendgrid_v5-1.2.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "7ede16d681cc0ce57c635f8617f0c31c",
                "sha256": "a5ebbdabb7c317defdf55fee67d1d062f54066e7579fc77b678a1d918890336f"
            },
            "downloads": -1,
            "filename": "django-sendgrid-v5-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7ede16d681cc0ce57c635f8617f0c31c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15603,
            "upload_time": "2022-12-22T20:41:28",
            "upload_time_iso_8601": "2022-12-22T20:41:28.436474Z",
            "url": "https://files.pythonhosted.org/packages/4a/51/a371b8816e55b289139311b85b9c51e81dd344b99c46761820b582e837a6/django-sendgrid-v5-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-22 20:41:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "sklarsa",
    "github_project": "django-sendgrid-v5",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-sendgrid-v5"
}
        
Elapsed time: 0.02164s