Python论坛  - 讨论区

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

2006年03月17日 星期五 08:30

charles huang hyy at fjii.com
Fri Mar 17 08:30:13 HKT 2006

wu ds_wu,您好! 

  smtp的论证方式多种多样,而且国内的一些邮件提供商还有一些比较特殊的防垃圾措施,就导致默认的login方法有时候会有问题,因此,建议用docmd来形成login指令,完成验证。

======== 2006-03-16 15:53:38 您在来信中写道: ========

我用了你的解决方法,可以发邮件了,谢谢啊
然后我看了一下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





= = = = = = = = = = = = = = = = = = = = = = 
        致
礼!

              charles huang
              hyy at fjii.com
                 2006-03-17
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060317/e6ae720e/attachment.html

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号