Google app engine send mail service raises excepti

2019-07-31 14:21发布

I was trying to use the app engine mail sending service on my site. Currently, I've put something as simple as:

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

But every time the code handler raises this error:

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

My code as a different version, and not the default one. I'm not able to change this version as the default version, unless this error gets resolved. Any idea why this is happening?

2条回答
【Aperson】
2楼-- · 2019-07-31 14:56

Seems to be a app engine system glitch. The same code is now working, without any new deployment.

查看更多
狗以群分
3楼-- · 2019-07-31 14:57

The sender must either have privilegies or be the logged in user. So subhranath@gmail.com should have admin rights to your location or be the logged in user to run your code.

Most basic example would be just a HTTP get to send an email:

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

If you want to send an email as the logged in user you can make the sender a variable:

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

I think the error message you posted was not very clear and if it persists I recommend to get more info about the error message using logging and exceptions.

查看更多
登录 后发表回答