根据文档,如果当前登录的用户拥有 Gmail 或 Google Apps 帐户,则可以使用 GAE 发送电子邮件:
为了安全起见,消息的发件人地址必须是
应用程序管理员的电子邮件地址或任何有效的
应用程序的电子邮件接收地址(请参阅接收邮件)。发件人
也可以是当前用户的 Google 帐户电子邮件地址
已登录(如果用户的帐户是 Gmail 帐户)或者是在
由 Google Apps 管理的域。
以下代码适用于代表 Gmail 用户发送电子邮件,但不适用于代表 Google Apps 用户发送电子邮件。尝试从 Google Apps 用户发送邮件会导致“未经授权的发件人”错误。
current_user = users.get_current_user()
message = mail.EmailMessage()
message.sender = current_user.email()
message.subject = 'subject text'
message.to = '[email protected]'
message.body = 'body text'
if message.is_initialized():
try:
message.send()
except Exception, e:
logging.error('Unable to send email update: %s' % e)
else:
logging.error('Email message improperly initialized')
我缺少什么?我还应该注意其他依赖项吗?
EDIT:
完整的堆栈跟踪:
Unauthorized sender
Traceback (most recent call last):
File "/base/data/home/apps/s~core-comps/1.358275951854397525/handler_cs_ticket.py", line 274, in sendEmailCopyToClient
message.send()
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 900, in send
raise ERROR_MAP[e.application_error](e.error_detail)
InvalidSenderError: Unauthorized sender
问题似乎在于您的应用程序正在使用联合登录,这是一项实验性功能,不适用于代表 Google Apps 帐户发送。您可以在管理控制台的“应用程序设置”页面上更改此设置。
我会将其添加到文档中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)