请给我一个简单明了的Python示例,展示如何使用App Engine发送HTML电子邮件。纯文本很简单,但我在处理HTML标签时遇到了困难。
请给我一个简单明了的Python示例,展示如何使用App Engine发送HTML电子邮件。纯文本很简单,但我在处理HTML标签时遇到了困难。
我没有测试过这个代码,所以请原谅可能存在的小错误。它基于来自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()
请查看这份文档。这就是您想要的。 http://code.google.com/appengine/docs/python/mail/emailmessagefields.html
html字段是电子邮件信息中的一个字段。 它包含了正文内容的HTML版本,方便那些喜欢HTML格式的收件人。
attachments字段用于添加电子邮件附件。
这里详细介绍了在App Engine上发送HTML电子邮件时可能遇到的一些问题:http://code.google.com/p/googleappengine/issues/detail?id=965