我尝试使用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==--
我看到的主要区别是编码和内容类型编码的引号。这是问题的根源,如果是,我该如何解决?
谢谢!
答案 0 :(得分:0)
我明白了 - https://developers.google.com/gmail/markup/registering-with-google更详细地解释了它。 Google允许向自己发送标记电子邮件,并显示所有标记。但是,为了让其他用户看到它,必须在从生产服务器发送副本后批准它。