谷歌Appengine发送电子邮件:[错误]未经授权发送

2024-06-07 06:37:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在我的网站上使用google app engine的邮件服务。每当我访问发送电子邮件的页面时,都会显示一些错误。错误显示我正在使用未经授权的发件人发送邮件。以下是发送电子邮件的代码:

mail.send_mail(sender="myapp@appspot.gserviceaccount.com",
     to=input_dict["email"],
     subject="Mondays user activation",
     body=content)

当我在本地尝试该站点时(使用dev_appserver.py),它不会显示错误,但不会发送电子邮件(注意:当我在本地尝试时,必须添加--enable_sendmail选项)。只有在我发布网站时才会出现此错误。

有人知道我做错了什么吗?提前谢谢你的帮助!


Tags: 代码sendapp网站电子邮件错误servicegoogle
3条回答

首先遵循以下步骤

https://cloud.google.com/appengine/docs/python/mail/#who_can_send_mail

然后需要在云控制台中手动添加发件人电子邮件

How to add an authorized sender

什么是myapp@appspot.gserviceaccount.com?您可能无法从该地址发送邮件。

App Engine applications can send email messages on behalf of the app's administrators, and on behalf of users with Google Accounts.

The email address of the sender, the From address. The sender address must be one of the following types:

  • The address of a registered administrator for the application. You can add administrators to an application using the Administration Console.

  • The address of the user for the current request signed in with a Google Account. You can determine the current user's email address with the Users API. The user's account must be a Gmail account, or be on a domain managed by Google Apps.

  • Any valid email receiving address for the app (such as xxx@APP-ID.appspotmail.com).

  • Any valid email receiving address of a domain account, such as support@example.com. Domain accounts are accounts outside of the Google domain with email addresses that do not end in @gmail.com or @APP-ID.appspotmail.com.

https://developers.google.com/appengine/docs/python/mail/sendingmail

您可能还必须将要从中发送电子邮件的电子邮件地址添加到应用程序引擎应用程序设置电子邮件API授权发件人。

https://cloud.google.com/appengine/docs/python/mail/#Python_Sending_mail

相关问题 更多 >