【问题标题】:Email markup not working with django send_email电子邮件标记不适用于 django send_email
【发布时间】:2017-04-30 12:59:42
【问题描述】:

我正在尝试使用 django 的 EmailMultiAlternatives 通过 gmail 帐户发送带有操作标记的电子邮件。我能够成功发送常规电子邮件,但我对电子邮件标记不满意。

我关注了Google's quickstart,这很有效。 html文件是

<html>
  <head>
    <script type="application/ld+json">
    {
      "@context":       "http://schema.org",
      "@type":          "EmailMessage",
      "description":    "Check this out",
      "potentialAction": {
        "@type": "ViewAction",
        "target":   "https://www.youtube.com/watch?v=eH8KwfdkSqU",
        "url": "https://www.youtube.com/watch?v=eH8KwfdkSqU"
      }
    }
    </script>
  </head>
  <body>
    <p>
      This a test for a Go-To action in Gmail.
    </p>
  </body>
</html>

收到的邮件来源如下:

Subject: Test Email markup - Wed Dec 14 2016 20:00:41 GMT-0600 (CST)
From: <my gmail>@gmail.com
To: <my gmail>@gmail.com
Content-Type: multipart/alternative; boundary=94eb2c11658811d31e0543a8d263

--94eb2c11658811d31e0543a8d263
Content-Type: text/plain; charset=UTF-8; format=flowed; delsp=yes

This a test for a Go-To action in Gmail.

--94eb2c11658811d31e0543a8d263
Content-Type: text/html; charset=UTF-8

<html>
  <head>
    <script type="application/ld+json">
    {
      "@context":       "http://schema.org",
      "@type":          "EmailMessage",
      "description":    "Check this out",
      "potentialAction": {
        "@type": "ViewAction",
        "target":   "https://www.youtube.com/watch?v=eH8KwfdkSqU",
        "url": "https://www.youtube.com/watch?v=eH8KwfdkSqU"
      }
    }
    </script>
  </head>
  <body>
    <p>
      This a test for a Go-To action in Gmail.
    </p>
  </body>
</html>
--94eb2c11658811d31e0543a8d263--

现在在 django,我有

subject = "Test Subject"
from_email = 'Name <%s>' % settings.EMAIL_HOST_USER
to = '<my gmail>@gmail.com'
text_content = 'This is an important message.'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(render_to_string('email/test.html'), "text/html")
msg.send()

其中 test.html 是与 Google 的 html 示例相同的模板文件。

收到的 django 电子邮件的电子邮件来源如下所示:

Content-Type: multipart/alternative; boundary="===============7033962557309231375=="
MIME-Version: 1.0
Subject: Test Subject
From: Name <gmail i'm sending from@gmail.com>
To: <my gmail>@gmail.com
Date: Thu, 15 Dec 2016 02:14:54 -0000
Message-ID: <20161215021454.14208.18492@MyComputer>

--===============7033962557309231375==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

This is an important message.
--===============7033962557309231375==
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <script type="application/ld+json">
    {
      "@context":       "http://schema.org",
      "@type":          "EmailMessage",
      "description":    "Check this out",
      "potentialAction": {
        "@type": "ViewAction",
        "target":   "https://www.youtube.com/watch?v=eH8KwfdkSqU"
      }
    }
    </script>
  </head>
  <body>
    <p>
      This a test for a Go-To action in Gmail.
    </p>
  </body>
</html>
--===============7033962557309231375==--

我看到的主要区别是编码和内容类型编码的引号。这是问题的根源吗?如果是,我该如何解决?

谢谢!

【问题讨论】:

    标签: python django html-email


    【解决方案1】:

    我想通了 - https://developers.google.com/gmail/markup/registering-with-google 更详细地解释了它。 Google 允许向您自己发送标记电子邮件,并且所有标记都将显示。但是,为了让其他用户看到它,必须在从生产服务器发送副本后获得批准。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2017-06-26
      相关资源
      最近更新 更多