免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6568 | 回复: 4
打印 上一主题 下一主题

[请教] python发送邮件失败,各位大侠帮忙看看 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-16 11:37 |只看该作者 |倒序浏览
发送邮件的代码如下:   
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做测试的, 用户名和密码是绝对正确的.
不知道这是为什么,哪位兄弟知道原因,麻烦告知一下,谢谢.
测试代码如下:
host = 'smtp.163.com'
src = "xxx@163.com"
des   = 'xxx@163.com
subject = "hi "
data = "this is test!!"
username = "xxx@163.com"
password = "yourkey"
try:
     send_email(host,src,des,subject,data,username,password)
     print 'success!!'
except Exception,e:
     print "error: %s" % str(e)

论坛徽章:
0
2 [报告]
发表于 2006-03-16 13:52 |只看该作者
我试了一下,这不是程序的问题。我用我们自己的邮件服务器的HOST,账号,密码,能正常发信的

论坛徽章:
0
3 [报告]
发表于 2006-03-23 21:50 |只看该作者
呵呵,常见现象,我开发的系统也遇到了,这是服务器本身设置问题。
去掉login那行认证,一般就可以了,这是relay方式。

论坛徽章:
0
4 [报告]
发表于 2006-03-24 09:49 |只看该作者
恩,这不错啊

论坛徽章:
0
5 [报告]
发表于 2006-03-24 10:52 |只看该作者
把这行代码
smtp.esmtp_features["auth"]="LOGIN PLAIN"
加在
smtp.login(account,password)
之前
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP