Python论坛  - 讨论区

标题:[python-chinese] python发送邮件失败, 不知道为什么

2006年03月16日 星期四 12:01

wu ds_wu dsongwu at gmail.com
Thu Mar 16 12:01:11 HKT 2006

发送邮件的代码如下:
def send_email(host,src,des,subject,data,account,password):
     """ send the email to user """
     try:
       Msg ['Subject'] = subject
       Msg ['From'] = src
       Msg ['To'] = des
       Msg = MIMEText(data,_subtype='plain',_charset='gb2312')

       print Msg
       smtp = smtplib.SMTP(host)
       smtp.login(account,password)
       smtp.sendmail(src,des,Msg.as_string())
       smtp.close()
     except Exception,e:
       raise Exception, str(e)
以上代码应该没什么问题吧?
但是每次执行到smtp.login那里就出错了,返回的错误是error: (535, 'Error: authentication failed')
我用的是smtp.163.com做测试的, 用户名和密码是绝对正确的.
不知道这是为什么,哪位兄弟知道原因,麻烦告知一下,谢谢.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060316/1c13e209/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 13:02

River Yan riverfor at gmail.com
Thu Mar 16 13:02:59 HKT 2006

python smtplib提供的操作接口是基于公共标准的操作接口。(由help(smtplib)得到)
而网易的smtp服务器作为商业的应用,在某些地方(如认证部分)做了相应的调整,这些调整导致smtplib的接口无法适应。

可执行
telnet smtp.163.com 25
EHLO ....
得到163的smtp相关信息...



--
riverfor's showtime.
riverfor's game

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 13:17

Xie Yanbo xieyanbo at gmail.com
Thu Mar 16 13:17:44 HKT 2006

On 3/16/06, wu ds_wu <dsongwu at gmail.com> wrote:
> 但是每次执行到smtp.login那里就出错了,返回的错误是error: (535, 'Error: authentication failed')
> 我用的是smtp.163.com做测试的, 用户名和密码是绝对正确的.

163和新浪的服务器需要helo或者ehlo指令,记得新浪的是要求必须放到
第一个指令来执行。而且他们对一些认证方式不支持,所以python的
smtplib自己判断并使用的auth方式不对,导致没法登录。我以前的解决
方法是使用LOGIN指令登录,比如这样:

def send(smtpserver, fromaddr, toaddr, user, pwd, msg):
    server = smtplib.SMTP(smtpserver)
    server.set_debuglevel(1)
    server.ehlo('xyb')
    #server.login(user, pwd)
    server.docmd("AUTH",
                 "%s %s" % ("LOGIN", encode_base64(user, eol="")))
    server.docmd(encode_base64(pwd, eol=""))
    server.sendmail(fromaddr, toaddr, msg)
    server.quit()

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 15:16

wu ds_wu dsongwu at gmail.com
Thu Mar 16 15:16:17 HKT 2006

怎么样才知道邮件服务器用什么方式认证的?
你的解决方法能不能解释一下代码,谢谢


在06-3-16,Xie Yanbo <xieyanbo at gmail.com> 写道:
>
> 163和新浪的服务器需要helo或者ehlo指令,记得新浪的是要求必须放到
> 第一个指令来执行。而且他们对一些认证方式不支持,所以python的
> smtplib自己判断并使用的auth方式不对,导致没法登录。我以前的解决
> 方法是使用LOGIN指令登录,比如这样:
>
> def send(smtpserver, fromaddr, toaddr, user, pwd, msg):
>    server = smtplib.SMTP(smtpserver)
>    server.set_debuglevel(1)
>    server.ehlo('xyb')
>    #server.login(user, pwd)
>    server.docmd("AUTH",
>                 "%s %s" % ("LOGIN", encode_base64(user, eol="")))
>    server.docmd(encode_base64(pwd, eol=""))
>    server.sendmail(fromaddr, toaddr, msg)
>    server.quit()
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060316/39d24700/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月16日 星期四 15:53

wu ds_wu dsongwu at gmail.com
Thu Mar 16 15:53:38 HKT 2006

我用了你的解决方法,可以发邮件了,谢谢啊
然后我看了一下python的smtplib的SMTP模块
发现它会自动发ehlo命令给服务器,根据服务器返回的信息
来选择不同的方式认证,你的方式实际上是就是里面的AUTH_LOGIN认证方式。
可是直接调用login方法让python来自动选择认证方式就是不行。好奇怪


在06-3-16,Xie Yanbo <xieyanbo at gmail.com> 写道:
>
> On 3/16/06, wu ds_wu <dsongwu at gmail.com> wrote:
> > 但是每次执行到smtp.login那里就出错了,返回的错误是error: (535, 'Error: authentication
> failed')
> > 我用的是smtp.163.com做测试的, 用户名和密码是绝对正确的.
>
> 163和新浪的服务器需要helo或者ehlo指令,记得新浪的是要求必须放到
> 第一个指令来执行。而且他们对一些认证方式不支持,所以python的
> smtplib自己判断并使用的auth方式不对,导致没法登录。我以前的解决
> 方法是使用LOGIN指令登录,比如这样:
>
> def send(smtpserver, fromaddr, toaddr, user, pwd, msg):
>    server = smtplib.SMTP(smtpserver)
>    server.set_debuglevel(1)
>    server.ehlo('xyb')
>    #server.login(user, pwd)
>    server.docmd("AUTH",
>                 "%s %s" % ("LOGIN", encode_base64(user, eol="")))
>    server.docmd(encode_base64(pwd, eol=""))
>    server.sendmail(fromaddr, toaddr, msg)
>    server.quit()
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060316/7219258d/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月17日 星期五 13:06

ask ask870 at 163.com
Fri Mar 17 13:06:44 HKT 2006

    如果从邮件服务器角度来看,请查看您的用户名后,是否应该加上后缀的域名,如应该为‘user at domain..com'而非’user',
    另外具体可以查看日志!


----- Original Message ----- 
From: "Xie Yanbo" <xieyanbo at gmail.com>
To: <python-chinese at lists.python.cn>
Sent: Thursday, March 16, 2006 1:17 PM
Subject: (瑞星提示-此邮件可能是垃圾邮件)Re: [python-chinese] python发送邮件失败, 不知道为什么


> On 3/16/06, wu ds_wu <dsongwu at gmail.com> wrote:
>> 但是每次执行到smtp.login那里就出错了,返回的错误是error: (535, 'Error: authentication failed')
>> 我用的是smtp.163.com做测试的, 用户名和密码是绝对正确的.
> 
> 163和新浪的服务器需要helo或者ehlo指令,记得新浪的是要求必须放到
> 第一个指令来执行。而且他们对一些认证方式不支持,所以python的
> smtplib自己判断并使用的auth方式不对,导致没法登录。我以前的解决
> 方法是使用LOGIN指令登录,比如这样:
> 
> def send(smtpserver, fromaddr, toaddr, user, pwd, msg):
>    server = smtplib.SMTP(smtpserver)
>    server.set_debuglevel(1)
>    server.ehlo('xyb')
>    #server.login(user, pwd)
>    server.docmd("AUTH",
>                 "%s %s" % ("LOGIN", encode_base64(user, eol="")))
>    server.docmd(encode_base64(pwd, eol=""))
>    server.sendmail(fromaddr, toaddr, msg)
>    server.quit()
>


--------------------------------------------------------------------------------


> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号