【问题标题】:Send HTML e-mail in App Engine / Python?在 App Engine / Python 中发送 HTML 电子邮件?
【发布时间】:2011-02-21 01:58:59
【问题描述】:

您能否给我一个使用 App Engine 发送 HTML 电子邮件的简单直接的 Python 示例?纯文本很简单,但我在使用 HTML 标记时遇到了困难。

【问题讨论】:

    标签: python google-app-engine email


    【解决方案1】:

    这详细说明了在 App Engine 上发送 HTML 电子邮件的一些问题:http://code.google.com/p/googleappengine/issues/detail?id=965

    【讨论】:

    • 不太关心附件或图像。只是基本的 HTML 功能,例如
    【解决方案2】:

    我还没有测试过,所以请原谅任何小错误。它基于 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']?它似乎对我不起作用。格式正确吗?
    【解决方案3】:

    请参阅此文档。这就是你想要的。 http://code.google.com/appengine/docs/python/mail/emailmessagefields.html

    电子邮件消息的

    html 字段。 正文内容的 HTML 版本,适用于喜欢 HTML 电子邮件的收件人。

    电子邮件附件的

    附件字段。

    【讨论】:

      猜你喜欢
      • 2016-12-04
      • 2010-10-27
      • 2012-04-10
      • 2016-10-27
      • 1970-01-01
      • 2012-03-24
      • 2015-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多