Python发送邮件

import smtplib
from email.mime.text import MIMEText
from email.header import Header

smtp = "smtp.qq.com"

sender = '发件人邮箱'
receiver = '收件人邮箱'
pwd = '授权码'

title = "HELLO WORLD"
contents = "来自{}的邮件".format(sender)


try:
    ldqplxo = MIMEText(contents, 'plain', 'utf-8')
    ldqplxo['From'] = Header(sender, 'utf-8')
    ldqplxo['To'] = Header(receiver, 'utf-8')
    ldqplxo['Subject'] = Header(title, 'utf-8')
    mbdrewr = smtplib.SMTP_SSL(smtp, 465)
    mbdrewr.login(sender, pwd)
    mbdrewr.sendmail(sender, receiver, ldqplxo.as_string())
    mbdrewr.quit()
except Exception as e:
    print('错误>>>', e)

原文地址:https://www.cnblogs.com/zhaogang0104/p/13034202.html