关于发邮件报错535 Error:authentication failed解决方法

相信看到535报错的同学代码编写方面都没有问题,只是不明白为什么填写了帐号密码后还是报535错误,这里我以163邮箱为例,并使用Python讲解怎么解决535问题

1. 先编写一个最简单的发邮件的python脚本

 1 #coding: utf-8  
 2 import smtplib
 3 from email.mime.text import MIMEText
 4 from email.header import Header
 5 
 6 sender = 'huochen1994@163.com'
 7 receiver = 'huochen1994@126.com'
 8 subject = 'python email test'
 9 smtpserver = 'smtp.163.com'
10 username = 'huochen1994@126.com'
11 password = '*********'
12 
13 msg = MIMEText( 'Hello Python', 'text', 'utf-8' )
14 msg['Subject'] = Header( subject, 'utf-8' )
15 
16 smtp = smtplib.SMTP()
17 smtp.connect( smtpserver )
18 smtp.login( username, password )
19 smtp.sendmail( sender, receiver, msg.as_string() )
20 smtp.quit()

2. 运行结果

1 Traceback (most recent call last):
2   File "mail.py", line 18, in <module>
3     smtp.login( username, password )  
4   File "/usr/lib64/python2.6/smtplib.py", line 589, in login
5     raise SMTPAuthenticationError(code, resp)
6 smtplib.SMTPAuthenticationError: (535, 'Error: authentication failed'

3. 解决方法

调用163邮箱服务器来发送邮件,我们需要开启POP3/SMTP服务,这时163邮件会让我们设置客户端授权码,这个授权码替代上面代码部分的passwd即可成功发送邮件

 

posted @ 2017-09-04 10:46  木棉花的漂泊  阅读(5628)  评论(0编辑  收藏  举报