目录

Google App Engine 发邮件

使用send_mail()函数发送邮件

from google.appengine.api import mail
 
mail.send_mail(sender="Example.com Support <support@example.com>",
              to="Albert Johnson <Albert.Johnson@example.com>",
              subject="Your account has been approved",
              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
""")

使用EmailMessage类发送邮件

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

GAE发送带附件邮件

发送附件必须使用EmailMessage类,EmailMessage带有attachments成员变量。

EmailMessage的attachment成员是一个list,一个tuple的list,tuple含有2个元素,文件名与文件内容。

参考