Submail的Django电子邮件后端。
django-submail的Python项目详细描述
使用Submail的pythonMail API发送电子邮件的简单django电子邮件后端。
要求
django=1.8。Django和其他版本不进行测试。
安装
从pypi安装后端:
pip install django-submail
将以下行添加到项目的settings.py或本地设置:
EMAIL_BACKEND="smbackend.SubmailBackend"SUBMAIL_APP_ID="Your Submail APPID"SUBMAIL_APP_KEY="Your Submail APPKey"
用法
如果您使用send_mail方法,您只需通过以下方法即可完成,例如:
fromdjango.core.mailimportsend_mailsend_mail("Your Subject","This is a pure text email body.","Dong Zhuang <hello@foo.com>",["dongzhuang@bar.com"])
如果要使用EmailMessage类,则:
fromdjango.core.mailimportEmailMessagemail=EmailMultiAlternatives(subject="Your Subject",body="This is a pure text email body.",from_email="Dong Zhuang <hello@example.com>",to=["dongzhuang@foo.com"],headers={"Reply-To":"dongzhuang@bar.com"})mail.send()
如果要使用EmailMultiAlternatives类,则:
fromdjango.core.mailimportEmailMultiAlternativesmail=EmailMultiAlternatives(subject="Your Subject",body="This is a pure text email body.",from_email="Dong Zhuang <hello@example.com>",to=["dongzhuang@foo.com"],headers={"Reply-To":"dongzhuang@bar.com"})mail.attach_alternative("<p>This is an HTML email body</p>","text/html")mail.send()
有时您需要使用默认子邮件应用程序ID以外的AppID发送其他电子邮件 在settings.py中设置,可以在中使用addSUBMAIL_APP_ID和SUBMAIL_APP_KEY键 标题,例如:
fromdjango.core.mailimportEmailMultiAlternativesmail=EmailMultiAlternatives(subject="Your Subject",body="This is a simple text email body.",from_email="Dong Zhuang <hello@example.com>",to=["dongzhuang@foo.com"],headers={"Reply-To":"dongzhuang@bar.com","SUBMAIL_APP_ID":settings.ANOTHER_APP_ID,"SUBMAIL_APP_KEY":settings.ANOTHER_APP_KEY})mail.attach_alternative("<p>This is an HTML email body</p>","text/html")mail.send()
演示
存储库中包含一个演示,您可以克隆git并在本地运行它。
您可以选择使用virtualenv运行演示。
pip install virtualenv virtualenv venv venv/scripts/activate
然后
pip install django
pip install django-submail
git clone https://github.com/dzhuang/django-submail.git
cd django-submail/demo
python manage.py migrate
复制本地设置示例:
cd demo
cp settings_local.py.example settings_local.py
vi settings_local.py
根据自己的需要在settings_local.py中编辑参数 子邮件应用程序,并编辑demo/test_smbackend/views.pyif 必要时,运行dev服务器:
cd ..
python manage.py runserver
访问http://127.0.0.1:8000查看结果。
待办事项
- 支持submail的mail/xsend api
- 支持Submail的通讯簿
许可证
麻省理工学院的执照。
贡献
Django Submail是完全开放源码的,欢迎任何形式的贡献。感觉 可以自由扩展它、报告错误或提供改进建议。 的作者可以通过dzhuang.scut@gmail.com联系。