gpt4 book ai didi

python - 代表 Google Apps 用户发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:53 26 4
gpt4 key购买 nike

根据文档,如果该用户拥有 Gmail 或 Google Apps 帐户,则可以代表当前登录的用户使用 GAE 发送电子邮件消息:

For security purposes, the sender address of a message must be the email address of an administrator for the application or any valid email receiving address for the app (see Receiving Mail). The sender can also be the Google Account email address of the current user who is signed in, if the user's account is a Gmail account or is on a domain managed by 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 = 'joe@example.com'
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')

我错过了什么?还有其他我应该注意的依赖关系吗?

编辑:

完整的堆栈跟踪:

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 帐户发送。您可以在管理控制台的“应用程序设置”页面上更改此设置。

我会将其添加到文档中。

关于python - 代表 Google Apps 用户发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10182854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com