一:授权密码管理

Python常用模块: 邮件 smtplib_python

二:发送邮件

邮箱

host

port

163

smtp.163.com

465

qq

smtp.qq.com

465

import smtplib
from email.mime.text import MIMEText

# 发送方邮箱地址
From = 'vbirdbest@163.com'
# 填入发送方邮箱的授权码,需要到发送方邮箱中设置
AuthCode = 'XXXXXXXXXXXXXXX'
# 收件人邮箱
To = 'itdarkhorse@163.com'
# 主题
subject = "python邮件测试"
# 正文
content = "content..."

msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = From
msg['To'] = To

try:
    # 邮件服务器及端口号
    s = smtplib.SMTP_SSL("smtp.163.com", 465)
    s.login(From, AuthCode)
    s.sendmail(From, To, msg.as_string())
    print("发送成功")
except Exception as e:
    print("发送失败")
finally:
    s.quit()

Python常用模块: 邮件 smtplib_邮件_02