开源软件名称:sklarsa/django-sendgrid-v5开源软件地址:https://github.com/sklarsa/django-sendgrid-v5开源编程语言:Python 99.7%开源软件介绍:django-sendgrid-v5This 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 How to Install
Other settings
UsageSimplefrom 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 DataFirst, create a dynamic template and copy the ID. 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)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) FAQHow to change a Sender's Name ?
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
Examples
Stargazers over time |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论