在学习的过程中遇到一些问题:

  1. 未设置客户端授权密码出现的报错: SMTPAuthenticationError: (550, b’User has no permission’)
    该问题是由于未设置授权密码出错,具体解决办法如下:

用Python发送邮件: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="[email protected]"    #用户名
mail_pass="****"   #授权码,注意不是邮箱登录密码,是上述设置的授权密码!!!
sender = '[email protected]'
receivers = ['[email protected]']  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

message = MIMEText('test', 'plain', 'utf-8')
message['From'] = "[email protected]"
message['To'] = "[email protected]"
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("邮件发送成功")

好了,问题解决了!

相关文章: