美文网首页
python 发送邮件

python 发送邮件

作者: 清晨起床敲代码 | 来源:发表于2018-07-30 17:37 被阅读0次

这里是最简单的一个例子,提前解决SSL验证的问题:
QQ:打开QQ邮箱--设置--账户--IMP/SMTP开启--手机验证--获取pwd码
163:设置--客户端授权密码--开启

import random
import smtplib
from email.mime.text import MIMEText

_user = "xxxxxxxx@163.com"
_pwd = "xxxxxxxxx"
_to = "xxxxxxx@163.com"

# 生成随机6位随机数字的密码
random_password = ''.join(str(i) for i in random.sample(range(0,9),6))

msg = MIMEText("新密码为:%s" % random_password )
msg["Subject"] = "主题"
msg["From"] = _user   # 可以输入任意字符串,隐藏邮箱地址
msg["To"] = _to

try:
    email_server = smtplib.SMTP_SSL("smtp.163.com", 465)
    email_server.login(_user, _pwd)
    email_server.sendmail(_user, _to, msg.as_string())
    email_server.quit()
    print("Success!")

except Exception as e:
    print("%s" % e)

相关文章

网友评论

      本文标题:python 发送邮件

      本文链接:https://www.haomeiwen.com/subject/vmofvftx.html