在GAE上从web2py发送邮件
我正在尝试从我在GoogleAppEngine上托管的web2py应用发送邮件,但一直没成功。我用了web2py自带的邮件功能。有没有人知道该怎么做?我在GAE的文档中看到,Python的邮件库在GAE上是不能用的,必须使用GAE的邮件库。这对web2py的邮件功能也适用吗?谢谢!
3 个回答
-1
你应该使用原生的 App Engine 邮件发送工具:http://code.google.com/appengine/docs/python/mail/sendingmail.html
3
web2py中的 gluon.tools.Mail
类可以在Google App Engine(GAE)上使用。你可以查看代码片段 gluon.tools
的第310行。
try:
if self.settings.server == 'gae':
from google.appengine.api import mail
result = mail.send_mail(sender=self.settings.sender, to=to,
subject=subject, body=text)
这是在GAE上工作的正确设置。
mail=Mail()
mail.settings.server="gae"
mail.settings.sender="you@example.com" #This must be the email address of a registered
#administrator for the application, or the address
#of the current signed-in user.
mail.settings.login="you:password"
请查看 http://code.google.com/intl/en/appengine/docs/python/mail/emailmessagefields.html 发件人 发件人的电子邮件地址,也就是“发件人”地址。这个地址必须是应用程序中注册的管理员的电子邮件,或者是当前登录用户的地址。你可以通过管理控制台将管理员添加到应用程序中。当前用户的电子邮件地址可以通过用户API获取。
抱歉!我的英语很差,希望能帮到你。
Celso Godinho (celso.gcosta@gmail.com) 2010年巴西世界杯冠军足球运动员
5
web2py中的gluon.tools.Mail类(也被Auth模块使用)可以在GAE(谷歌应用引擎)和非GAE环境下直接使用。你只需要提供正确的设置:
mail=Mail()
mail.settings.server="smtp.example.com:25" or "gae"
mail.settings.sender="you@example.com"
mail.settings.tls=True or False
mail.settings.login="you:password"
它支持多种编码方式、MIME类型和附件功能。