Django的Mandrill事务电子邮件
djrill的Python项目详细描述
PROJECT STATUS: INACTIVE
As of April, 2016, Djrill is no longer actively maintained (other than security updates). It is likely to keep working unless/until Mandrill changes their APIs, but Djrill will not be updated for newer Django versions or Mandrill changes. (more info)
You may be interested in django-anymail, a Djrill fork that supports Mailgun, Postmark, SendGrid, and other transactional ESPs (including limited support for Mandrill).
一般来说,djrill与django的内置^{tt1}一起“工作”$ 包裹。它包括:
- 支持HTML、附件、额外标题和 Django’s built-in email
- 特定于Mandrill的扩展,如标记、元数据、跟踪和MailChimp模板
- 可选支持Mandrill入站电子邮件和其他Webhook通知, 通过Django信号
Djrill是根据BSD许可证发布的。对django 1.4-1.9进行了测试 (包括Python3和Django1.6+,以及Pypy支持Django1.5+)。 djrill使用semantic versioning。
资源
- 完整文档:https://djrill.readthedocs.org/en/v2.1/
- pypi上的包:https://pypi.python.org/pypi/djrill
- github上的项目:https://github.com/brack3t/Djrill
djrill 1-2-3
从pypi安装djrill:
$ pip install djrill
编辑项目的settings.py:
INSTALLED_APPS=(..."djrill")MANDRILL_API_KEY="<your Mandrill key>"EMAIL_BACKEND="djrill.mail.backends.djrill.DjrillBackend"DEFAULT_FROM_EMAIL="you@example.com"# if you don't already have this in settings
现在是常规的Django email functions 将通过卷轴发送:
fromdjango.core.mailimportsend_mailsend_mail("It works!","This will get sent through Mandrill","Djrill Sender <djrill@example.com>",["to@example.com"])
您可以发送一条html消息,其中包含自定义的mandrill标记和元数据:
fromdjango.core.mailimportEmailMultiAlternativesmsg=EmailMultiAlternatives(subject="Djrill Message",body="This is the text email body",from_email="Djrill Sender <djrill@example.com>",to=["Recipient One <someone@example.com>","another.person@example.com"],headers={'Reply-To':"Service <support@example.com>"}# optional extra headers)msg.attach_alternative("<p>This is the HTML email body</p>","text/html")# Optional Mandrill-specific extensions:msg.tags=["one tag","two tag","red tag","blue tag"]msg.metadata={'user_id':"8675309"}# Send it:msg.send()
见full documentation 更多功能和选项。