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

25

请给我一个简单明了的Python示例,展示如何使用App Engine发送HTML电子邮件。纯文本很简单,但我在处理HTML标签时遇到了困难。

3个回答

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()

如果我想发送电子邮件给多个收件人,文档中说应该是一个字符串列表。像这样['user1@example.com','user2@example2.com']?但它似乎对我不起作用。格式正确吗? - kassold

4

0

并不关心附件或图片,只需要基本的HTML功能,如<hr> <b>等。 - Silver Dragon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接