这里会显示出您选择的修订版和当前版本之间的差别。
— |
google:gae:send-mail [2011/04/27 14:13] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Google App Engine 发邮件 ====== | ||
+ | ===== 使用send_mail()函数发送邮件 ===== | ||
+ | |||
+ | <code python> | ||
+ | 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 | ||
+ | """) | ||
+ | </code> | ||
+ | |||
+ | |||
+ | ===== 使用EmailMessage类发送邮件 ===== | ||
+ | |||
+ | <code python> | ||
+ | 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() | ||
+ | </code> | ||
+ | ===== GAE发送带附件邮件 ===== | ||
+ | 发送附件必须使用EmailMessage类,EmailMessage带有attachments成员变量。 | ||
+ | |||
+ | EmailMessage的attachment成员是一个list,一个tuple的list,tuple含有2个元素,文件名与文件内容。 | ||
+ | |||
+ | |||
+ | ===== 参考 ===== | ||
+ | * http://code.google.com/appengine/docs/python/mail/sendingmail.html |