@rickyChen
2016-04-29T07:15:38.000000Z
字数 995
阅读 15742
其他
相信看到535报错的同学们代码编写方面都没有问题,只是不明白为什么填写了帐号密码后还是报535错误,这里我以163邮箱为例,并使用Python讲解怎么解决535问题
#coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Headersender = 'huochen1994@163.com'receiver = 'huochen1994@126.com'subject = 'python email test'smtpserver = 'smtp.163.com'username = 'huochen1994@126.com'password = '*********'msg = MIMEText( 'Hello Python', 'text', 'utf-8' )msg['Subject'] = Header( subject, 'utf-8' )smtp = smtplib.SMTP()smtp.connect( smtpserver )smtp.login( username, password )smtp.sendmail( sender, receiver, msg.as_string() )smtp.quit()
如果在上述代码username和password,变量中填写邮箱的帐号密码那么会看到以下报错:
Traceback (most recent call last):File "mail.py", line 18, in <module>smtp.login( username, password )File "/usr/lib64/python2.6/smtplib.py", line 589, in loginraise SMTPAuthenticationError(code, resp)smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed')
调用163邮箱服务器来发送邮件,我们需要开启POP3/SMTP服务,这时163邮件会让我们设置客户端授权码,这个授权码替代上面代码部分的passwd即可成功发送邮件
