在App Engine/Python中发送HTML电子邮件?

Sil*_*gon 25 python email google-app-engine

你能给我一个简单,直接的python示例,使用App Engine发送HTML电子邮件吗?明文很简单,但我对HTML标签有困难.

ʇsә*_*ɹoɈ 54

我没有测试过这个,所以请原谅任何小错误.它基于Google文档中的示例:http: //code.google.com/appengine/docs/python/mail/sendingmail.html

from google.appengine.api import mail

message = mail.EmailMessage(sender="Example.com Support <support@example.com>",
                            subject="Your account has been approved")

message.to = "Albert Johnson <Albert.Johnson@example.com>"

message.body = """
Dear Albert:

Your example.com account has been approved.  You can now visit
http://www.example.com/ and sign in using your Google Account to
access new features.

Please let us know if you have any questions.

The example.com Team
"""

message.html = """
<html><head></head><body>
Dear Albert:

Your example.com account has been approved.  You can now visit
http://www.example.com/ and sign in using your Google Account to
access new features.

Please let us know if you have any questions.

The example.com Team
</body></html>
"""

message.send()
Run Code Online (Sandbox Code Playgroud)