2016-12-15 30 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==-- 

我看到的主要區別是圍繞編碼的報價和內容類型編碼。這是問題的根源,如果是的話,我該如何解決它?

謝謝!

回答