标签:image .com code imp SM user end list host
开通QQ邮箱IMAP/SMTP服务,忘记了,重新开通一下,记住密码串。
import smtplib from email.mime.text import MIMEText # 收件人列表 mail_namelist = [email] # 发送方信息 mail_user = settings.EMAIL_HOST_USER # 口令 mail_pass = settings.EMAIL_HOST_PASSWORD try: msg = MIMEText(str(email_body)) # 设置标题 msg["Subject"] = email_title # 发件邮箱 msg["From"] = mail_user # 收件邮箱 msg["To"] = ";".join(mail_namelist) # 设置服务器、端口 s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 登录邮箱 s.login(mail_user, mail_pass) # 发送邮件 s.sendmail(mail_user, mail_namelist, msg.as_string()) s.quit() print("邮件发送成功!") return True except smtplib.SMTPException: print("邮件发送失败!") return False
settings中:
EMAIL_HOST = ‘smtp.qq.com‘ EMAIL_PORT = ‘465‘ EMAIL_HOST_USER = ‘admin@qq.com‘ EMAIL_HOST_PASSWORD = ‘aytbcpitdwbxbwfw‘ EMAIL_USE_TLS = True EMAIL_FROM = ‘admin@qq.com‘
效果:
python3.6 django2.06 使用QQ邮箱发送邮件
标签:image .com code imp SM user end list host
原文地址:https://www.cnblogs.com/andu99/p/9197597.html