sendgrid api的django电子邮件后端
django-sgapi的Python项目详细描述
SendGrid API的Django电子邮件后端
安装
从pypi安装后端:
pip install django-sgapi
在项目的settings.py中添加以下内容:
EMAIL_BACKEND="sgbackend.SendGridBackend"SENDGRID_API_KEY="Your SendGrid API Key"
完成!
示例
fromdjango.core.mailimportsend_mailfromdjango.core.mailimportEmailMultiAlternatives# Send a simple messagesend_mail('Hello there!','Emails are the future!','Jay Hale <jay@jtst.io>',['hello@sink.sendgrid.net'])# Send a more complex messagemail=EmailMultiAlternatives(subject='Hello there again!',body='Who knew you could do so many things with email?!?',from_email='Jay Hale <jay@jtst.io>',to=['hello@sink.sendgrid.net'],)mail.reply_to='No Reply <no-reply@sink.sendgrid.net>'mail.template_id='marketing_template_5'mail.substitutions={'%organization%':'jtstio'}withopen('flyer.pdf','rb')asfile:mail.attachments=[('flyer.pdf',file.read(),'application/pdf')]mail.attach_alternative("<p>Who knew you could do <strong>so many things</strong> with email?!?</p>","text/html")mail.send()
许可证
麻省理工学院
享受:)