在学习的过程中遇到一些问题:
- 未设置客户端授权密码出现的报错: SMTPAuthenticationError: (550, b’User has no permission’)
该问题是由于未设置授权密码出错,具体解决办法如下:
改好之后运行以下代码即可:
import smtplib
from email.mime.text import MIMEText
from email.header import Header
mail_host="smtp.163.com" #设置服务器
mail_user="tina_huanghui@163.com" #用户名
mail_pass="****" #授权码,注意不是邮箱登录密码,是上述设置的授权密码!!!
sender = 'tina_huanghui@163.com'
receivers = ['425845636@qq.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
message = MIMEText('test', 'plain', 'utf-8')
message['From'] = "tina_huanghui@163.com"
message['To'] = "425845636@qq.com"
subject = 'test email'
message['Subject'] = Header(subject, 'utf-8')
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25)
smtpObj.set_debuglevel(1)
smtpObj.login(mail_user,mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
好了,问题解决了!