python通过smtp发送qq邮件
import smtplib
from email.mime.text import MIMEText
from email.header import Header


\"\"\"
1》测试邮件发送
2》有收件人、发件人、主题、邮件内容
\"\"\"

sender = \'xx@qq.com\'
receivers = [\'xx@qq.com\', \'xx@qq.com\'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

# 三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
message = MIMEText(\'您好! 我的账号不能写博客,麻烦解封一下,谢谢\', \'plain\', \'utf-8\')
message[\'From\'] = sender
message[\'To\'] = \';\'.join(receivers)

subject = \'账号解封\'
message[\'Subject\'] = Header(subject, \'utf-8\')

smtpObj = smtplib.SMTP(\'smtp.qq.com\', 25)
smtpObj.starttls()
smtpObj.login(sender, \'stmp授权密码\')
smtpObj.sendmail(sender, receivers, message.as_string())
print(\'success\')

 

遇到的问题:

  • smtplib.SMTPAuthenticati : (535, b\'Error..)

  授权失败,刚开始smtpObj.login(sender, \'stmp授权密码\'),传入的密码是qq密码,需要qq邮箱设置中开启smtp服务,获得授权码

  \"\"

 



收藏 打印