在gmail上从GAE dev_appserver发送邮件时,SMTPSenderRefused [英] SMTPSenderRefused when sending mail from GAE dev_appserver on gmail

查看:178
本文介绍了在gmail上从GAE dev_appserver发送邮件时,SMTPSenderRefused的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的电子邮件相关的dev_appserver选项:
$ b

- smtp_host = smtp.gmail.com --smtp_port = 25 --smtp_user = me@mydomain.com --smtp_password =password



现在,这仍然无效,每次Google发布新的dev_appserver根据此 S / O答案,我必须编辑api / mail_stub.py才能在本地工作。



但是,即使这种解决方法现在已停止工作。我收到以下异常:

SMTPSenderRefused:(555,'5.5.2 Syntax error。mw9sm14633203wib.0 - gsmtp',< email。 header.Header实例在0x10c9c9248>)



有谁比我更聪明知道如何解决它?



更新
我可以通过使用电子邮件地址(例如,发件人和收件人)以简单字符串的普通格式获得发送给dev_appserver的电子邮件( name @ domain.com )而不是使用尖括号样式(名称< name@domain.com> )。这不是生产中的问题:收件人和发件人电子邮件地址可以在 mail.send_mail 调用中使用尖括号。我提出了关于dev_appserver和production之间的这种不同行为的票: https://code.google.com/p/googleappengine/issues/detail?id=10211&thanks=10211&ts=1383140754

在我的测试中,当一个像'Name'这样的'From'字符串被传入 smtplib.SMTP.sendmail ,它解析字符串以找到尖括号内的部分(如果有的话)用作SMTP发件人,给。然而,如果这个参数是一个email.header.Header,那么只是转换为字符串并且不用进一步解析就使用它,给出>,从而导致我们看到的问题。



以下是我刚发布在上的补丁问题跟踪器到谷歌/ appengine / api / mail_stub.py将此参数转换回字符串(适用于我):

  --- google / appengine / api / mail_stub-orig.py 2014-12-12 20:04:53.612070031 +0000 
+++ google / appengine / api / mail_stub.py 2014-12- 12 20:05:07.532294605 +0000
@@ -215,7 +215,7 @@


tos = [mime_message [to] for to in ['To' ,'Cc','Bcc'] if mime_message [to]]
- smtp.sendmail(mime_message ['From'],tos,mime_message.as_string())
+ smtp.sendmail(str mime_message ['From']),tos,mime_message.as_string())
finally:
smtp.quit()


Here are my email related dev_appserver options:

--smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=me@mydomain.com --smtp_password="password"

Now, this still doesn't work and every time Google release a new dev_appserver I have to edit api/mail_stub.py to get things to work locally as per this S/O answer.

However, even this workaround has now stopped working. I get the following exception:

SMTPSenderRefused: (555, '5.5.2 Syntax error. mw9sm14633203wib.0 - gsmtp', <email.header.Header instance at 0x10c9c9248>)

Does anyone smarter than me know how to fix it?

UPDATE I was able to get email to send on dev_appserver by using email addresses (eg. for sender and recipient) in their 'plain' format of a simple string (name@domain.com) rather than using the angle bracket style (Name <name@domain.com>). This is not a problem in production: recipients and sender email addresses can use angle brackets in the mail.send_mail call. I raised a ticket about this divergent behaviour between dev_appserver and production: https://code.google.com/p/googleappengine/issues/detail?id=10211&thanks=10211&ts=1383140754

解决方案

Looks like it's because the 'sender' is now stored as a "email.header.Header" instance in the dev server instead of a string (since SDK 1.8.3 I think).

From my testing, when a 'From' string like "Name " is passed into smtplib.SMTP.sendmail, it parses the string to find the part within angle brackets, if any, to use as the SMTP sender, giving "". However, if this parameter is an "email.header.Header", then is just converts to string and uses it without further parsing, giving ">", thus causing the problem we're seeing.

Here's the patch I just posted on the issue tracker to google/appengine/api/mail_stub.py to convert this parameter back to a string (works for me):

--- google/appengine/api/mail_stub-orig.py      2014-12-12 20:04:53.612070031 +0000
+++ google/appengine/api/mail_stub.py   2014-12-12 20:05:07.532294605 +0000
@@ -215,7 +215,7 @@


       tos = [mime_message[to] for to in ['To', 'Cc', 'Bcc'] if mime_message[to]]
-      smtp.sendmail(mime_message['From'], tos, mime_message.as_string())
+      smtp.sendmail(str(mime_message['From']), tos, mime_message.as_string())
     finally:
       smtp.quit()

这篇关于在gmail上从GAE dev_appserver发送邮件时,SMTPSenderRefused的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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