代表Google Apps用户发送电子邮件 [英] Sending email on behalf of Google Apps user

查看:157
本文介绍了代表Google Apps用户发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



< blockquote>

出于安全考虑,邮件的发件人地址必须是应用程序管理员的
电子邮件地址或应用程序的任何有效的
电子邮件接收地址(请参阅接收邮件)。如果用户的帐户是Gmail帐户或位于由Google管理的
域中,发件人
也可以是当前登录
的用户的Google帐户电子邮件地址以下代码适用于代表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()
除了Exception,e:
logging.error('无法发送电子邮件更新:%s'%e)
其他:
logging.error('电子邮件不正确初始化')

我错过了什么?是否还有其他的依赖关系,我应该知道的?



编辑:



完整堆栈跟踪:

 未经授权的发件人
追踪(最近的最后一次通话):
文件/ base / data / home / apps / s 〜core-comps / 1.358275951854397525 / handler_cs_ticket.py,第274行,在sendEmailCopyToClient
message.send()
文件/ base / python_runtime / python_lib / versions / 1 / google / appengine / api / mail .py,第900行,发送
ERROR_MAP [e.application_error](e.error_detail)
InvalidSenderError:未授权发件人


解决方案

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



我将其添加到文档中。


According to the documentation it is possible to send an email message using GAE on behalf of the currently logged in user, if that user has a Gmail or Google Apps account:

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.

The following code works for sending emails on behalf of Gmail users but not Google Apps users. Attempting to send mail from a Google Apps user results in an 'Unauthorized sender' error.

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')

What am I missing? Are there other dependencies that I should be aware of?

EDIT:

Full stacktrace:

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

解决方案

It looks like the problem is that your application is using Federated Login, which is an experimental feature and doesn't work with sending on behalf of Google Apps accounts. You can change this on the "Application Settings" page in the admin console.

I'll add this to the documentation.

这篇关于代表Google Apps用户发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆