Reputation: 83
I'm trying to send emails with action markup through a gmail account using django's EmailMultiAlternatives. I am able to successfully send regular emails, but am not having luck with the email markup.
I followed Google's quickstart and that works. The html file is
<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>
The received email source looks like:
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--
Now in django, I have
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()
where test.html is a template file identical to Google's html example.
The received email source for the django email looks like:
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: <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==--
The main difference I see is the quotes around encoding and the content type encoding. Is that the root of the problem, and if so how do I fix it?
Thank you!
Upvotes: 0
Views: 433
Reputation: 83
I figured it out - https://developers.google.com/gmail/markup/registering-with-google explains it in more detail. Google allows sending markup emails to yourself and all markup will be displayed. However, in order for other users to see it, it must be approved after sending a copy from a production server.
Upvotes: 1