为何无法登陆163邮箱
import smtplibfrom email.mime.text import MIMEText
from email.header import Header
sender = 'baokonganti@163.com'
receiver = 'xyz@gmail'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = 'antibaokong'
password = '******'
msg = MIMEText('你好','text','utf-8')#中文需参数‘utf-8’,单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()
上面的代码,运行时,出现错误,
>>> smtp.login(username, password)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python34\lib\smtplib.py", line 639, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')
密码,我手工测试过,没有问题,为何会这样?
sender = 'baokonganti@163.com'
username = 'antibaokong'
发送邮箱和用户名不一致吧 用户名用全称, 带 163.com 试试.
另外, 楼上说过了, sender 必须和 username 是同一个, 否则, 一样不会发成功.sender = 'baokonganti@163.com'
username = 'antibaokong'=> username = 'baokonganti@163.com'
页:
[1]