2016-12-15 32 views
0

我试图通过使用django的EmailMultiAlternatives的gmail帐户发送带有动作标记的电子邮件。我能够成功发送定期的电子邮件,但没有电子邮件标记的运气。电子邮件标记不与django一起使用send_email

我跟着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是一个模板文件等同于谷歌的HTML例。

为Django的电子邮件收到的电子邮件来源的样子:

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

--===============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==-- 

我看到的主要区别是围绕编码的报价和内容类型编码。这是问题的根源,如果是的话,我该如何解决它?

谢谢!

回答