【问题标题】:Google app engine send mail service raises exception谷歌应用引擎发送邮件服务引发异常
【发布时间】:2023-03-07 18:57:01
【问题描述】:

我试图在我的网站上使用应用引擎邮件发送服务。 目前,我提出了如下简单的内容:

message = mail.EmailMessage(sender="Subhranath Chunder <subhranath@gmail.com>", \
                                    subject="Your account has been approved")
message.to = "Subhranath Chunder <subhranathc@yahoo.com>"
message.body = "Just another message"
message.send()

但每次代码处理程序引发此错误时:

2011-08-20 04:44:36.988
ApplicationError: 1 Internal error
Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 703, in __call__
    handler.post(*groups)
  File "/base/data/home/apps/s~subhranath/0-2.352669327317975990/index.py", line 71, in post
    message.send()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 895, in send
    raise e
ApplicationError: ApplicationError: 1 Internal error

我的代码是另一个版本,而不是默认版本。我无法将此版本更改为默认版本,除非此错误得到解决。知道为什么会这样吗?

【问题讨论】:

    标签: google-app-engine


    【解决方案1】:

    发件人必须具有特权或者是登录用户。所以 subhranath@gmail.com 应该拥有您所在位置的管理员权限,或者是登录用户来运行您的代码。

    最基本的例子就是发送电子邮件的 HTTP get:

      def get(self):    
        message = mail.EmailMessage(sender='subhranath_app_admin@gmail.com', subject='Email')
        message.to='any...@gmail.com'
        message.body = os.environ.get('HTTP_HOST')      
        message.send() 
    

    如果您想以登录用户的身份发送电子邮件,您可以将发件人设为变量:

    senderemail = users.get_current_user().email() if users.get_current_user() else 'subhranath@gmail.com'
    

    我认为您发布的错误消息不是很清楚,如果它仍然存在,我建议您使用日志记录和异常获取有关错误消息的更多信息。

    【讨论】:

    • 用户 'subhranath@gmail.com' 是应用程序的唯一管理员,也就是我。 :) 几个小时前,相同的代码才开始工作。我什至没有进行新的部署。 :(
    【解决方案2】:

    似乎是应用引擎系统故障。相同的代码现在可以运行,没有任何新的部署。

    【讨论】:

      猜你喜欢
      • 2012-06-13
      • 2011-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 1970-01-01
      • 2011-06-01
      相关资源
      最近更新 更多