【问题标题】:Sending email on behalf of Google Apps user代表 Google Apps 用户发送电子邮件
【发布时间】:2012-04-16 22:55:37
【问题描述】:

根据文档,如果该用户拥有 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 = '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

【问题讨论】:

  • 不要使用logging.error,使用logging.exception,它将为您记录堆栈跟踪。请不要,不要,不要这样做except Exception, e!不过,请务必在您的问题中包含完整的堆栈跟踪。
  • 您尝试过使用许多 Google Apps 帐户吗?如果您向我发送(通过电子邮件很好,我是 google.com 的名字 + 姓氏首字母),我可以尝试追踪此问题。谢谢!
  • @Moishe - 感谢您的提议,我已将帐户详细信息通过电子邮件发送给您,是的,我已尝试使用多个 Google Apps 帐户。

标签: python google-app-engine


【解决方案1】:

问题似乎在于您的应用程序正在使用联合登录,这是一项实验性功能,不适用于代表 Google Apps 帐户发送。您可以在管理控制台的“应用程序设置”页面上更改此设置。

我会将其添加到文档中。

【讨论】:

    猜你喜欢
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 2016-04-12
    相关资源
    最近更新 更多