【问题标题】:Using MailChimp with SendGrid将 MailChimp 与 SendGrid 一起使用
【发布时间】:2012-09-10 05:09:08
【问题描述】:

我使用他们的模板生成器在 MailChimp 中构建了一个电子邮件模板。

我想将这封电子邮件发送给某些事件的个人。例如,如果有人忘记了密码,我想向他们发送我在 MailChimp 中创建的“忘记密码”模板。

我查看了 MailChimp 的 API,但它似乎对非批量电子邮件发送不太友好。我将如何使用从 MailChimp 创建的 HTML 模板但使用 SendGrid for SMTP 发送这样的交易电子邮件?

代码如下所示:

if action == 'forgot_password':
    email = mailchimp.get_template(forgot_password)
    sendgrid.send_mail(user, subject, email, from)

【问题讨论】:

    标签: python email html-email mailchimp sendgrid


    【解决方案1】:

    这正是 MailChimp 的 Mandrill transactional mail service 的用途 - 它还允许某些级别的模板重用。

    【讨论】:

      【解决方案2】:

      不确定您使用什么 Mailchimp 库来获取模板。做了一些谷歌搜索并无法弄清楚,但假设 get_template 返回电子邮件的 html 内容,您可以这样做:

      import sendgrid
      
      s = sendgrid.Sendgrid('username', 'password', secure=True)
      
      if action == 'forgot_password'
        html = mailchimp.get_template(forgot_password)
        message = sendgrid.Message("from@mydomain.com", "subject", text_version_of_template, html)
        message.add_to("someone@example.com", "John Doe")
        s.smtp.send(message)
      

      有关获取 html 的文本版本的详细信息,请参阅 this question

      【讨论】:

        猜你喜欢
        • 2014-12-31
        • 1970-01-01
        • 1970-01-01
        • 2014-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多