Django的增强电子邮件类

django-enhanced-emails的Python项目详细描述


Django增强电子邮件

电池包括Django的电子邮件。

  • 强大的模板引擎
  • 默认情况下,多部分电子邮件(HTML+文本)
  • Web版本呈现(带管理员)
  • 简易文件附件
  • 还有更多…

开始

简单设置

  • 安装程序包:pipenv install django-enhanced-emails

  • 创建新的电子邮件类:

    # myapp/emails.pyfromenhanced_emailsimportEnhancedEmailclassWelcomeEmail(EnhancedEmail):subject="Welcome to our site!"html_template="emails/welcome.html"
    <!-- myapp/templates/emails/welcome.html --><strong>Welcome to our site {{first_name}}!</strong><br/>
    
    Best, The OurSite team
    
  • 实例化电子邮件并发送:

    email=WelcomeEmail(to=[user.email],context={"first_name":user.first_name})email.send()
  • 全部完成!我们的用户收到了如下信息:

    Content-Type: multipart/alternative;
    boundary="===============7747654958126582044=="
    MIME-Version: 1.0
    Subject: hello
    From: hello@oursite.com
    To: user@gmail.com
    Date: Wed, 11 Apr 2018 17:13:02 -0000
    Message-ID: <152346678269.275.17989388690220812241@cf7f5f3375c9>
    
    --===============7747654958126582044==
    Content-Type: text/plain; charset="utf-8"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    
    Welcome to our site Elon!
    
    Best,
    The OurSite team
    --===============7747654958126582044==
    Content-Type: text/html; charset="utf-8"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    
    <strong>Welcome to our site Elon!</strong>
    
    Best,
    The OurSite team
    --===============7747654958126582044==--
    

高级设置(用于Web版本呈现)

  • enhanced_emails应用程序添加到INSTALLED_APPS

    # settings.pyINSTALLED_APPS=[..."enhanced_emails",...]
  • 将新条目添加到urlpatterns

    # urls.pyurlpatterns=[path("admin/",admin.site.urls),path("emails/",include("enhanced_emails.urls")),...]
  • 使用WebVersionEnhancedEmail而不是EnhancedEmail

    fromenhanced_emailsimportWebVersionEnhancedEmailclassWelcomeEmail(WebVersionEnhancedEmail):subject="Welcome to our site!"html_template="emails/welcome.html"
  • 使用电子邮件模板中的web_url变量:

    <!-- myapp/templates/emails/welcome.html --><strong>Welcome to our site {{ first_name }}!</strong><br/>
    
    Best, The OurSite team<br/><ahref="{{ web_url }}">View in browser</a>
  • 实例化一封电子邮件并发送(请注意,我们现在也需要传递请求):

    email=WelcomeEmail(to=[user.email],context={'first_name':user.first_name},request=request)email.send()
  • 电子邮件在管理员和网站上都可见!
    A sent email in the adminThe web version of the email

开发

  • 部署:python setup.py sdist && twine upload dist/*

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在href中将struts2文本字段的值作为参数传递?   java检查对象属性是否为空的最佳方法是什么?   java通过Maven使用Junit类别运行Cucumber测试   java如何在selenium Webdriver(Mac)中使用Robot类上传多个文件?   如何用python绘制图形或将python转换为java和Matlab?   java Osgi捆绑包更新和ResourceBundle   java使用流api将流<@Nullable T>转换为流<@NonNull T>   java中EXCEL的平台无关连接字符串   JavaFX中的java表   java Jetty线程池和sun。HttpServer会话   JPA存储库bean的java Spring注入无法工作NullPointerException   java从另一个Kubernetes作业触发Kubernetes   我的java netbeans抽奖计划需要帮助吗   泛型中的java有界类型无法扩展另一个有界类型   如果混合使用全局构建和概要文件构建,java cxfcodegenplugin会生成错误代码   封装SQL平台之间差异的java策略?