Escapado
Escapado

Reputation: 117

How to use HTML in Google App Engine Mail API

I'm currently setting up email verification for my website that is working with google app engine. I want the users to click a verification link and I would also like to style the email a little using html and css. So I have my python script all set up. And I have a mail objekt and I do this:

   mail.send_mail(sender="...",
     to=".....",
     subject="Verification Mail"
     body="""
Dear ....
Thanks for signing up on example.com
Please click the link below to verify your email adress.
http://example.com/verifymail?email="""+adress+""""&hash="""+hash+"""
We hope you enjoy our platform.

   """)

Now this works perfectly fine. But what I would like is to place an anchor tag inside my mail like

<a href='http://example.com/verifymail?email="""+adress+""""&hash="""+hash+"""'>Verify Email</a>

But doing that will literally print out the html source inside the mail, instead of understanding this as HTML. (It correctly fills in the variables btw). I would also like to add some more things to the newsletter but I guess getting it to understand the tags at all would solve all my problems.

Is there any solution to this?

Upvotes: 0

Views: 544

Answers (1)

Zz&#39;Rot
Zz&#39;Rot

Reputation: 904

The reason that your email is interpreted as plain text instead of HTML is that body is interpreted as plain text.

In order for your content to be interpreted as HTML, you will need to set the html attribute as the HTML version of the email, i.e. add something like html="<h3>Hello World</h3>". Check the official API for reference: https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.mail

More background about content type: some email clients cannot interpret HTML messages, so usually both HTML and plain text version are sent to the user to guarantee compatibility. That's why an email has both "plain text" and "HTML" fields.

Upvotes: 1

Related Questions