发送邮件


import smtplib
from email.mime.text import MIMEText

def send_mail(receiver_address, content):
    """发送邮件通知"""
    # 连接邮箱服务器信息
    host = 'smtp.163.com'
    port = 25
    sender = 'wztshine@163.com'  # 发件邮箱
    pwd = 'xxxxx'  # 不是登陆密码,是客户端授权密码
    # 发件信息
    body = '<h2>温馨提醒:</h2><p>' + " "+content + '</p>'
    msg = MIMEText(body, 'html', _charset="utf-8")
    msg['subject'] = '你好!'  # 邮件主题
    msg['from'] = sender
    msg['to'] = receiver_address
    s = smtplib.SMTP(host, port)
    # 开始登陆邮箱,并发送邮件
    s.login(sender, pwd)
    s.sendmail(sender, receiver_address, msg.as_string())
    s.quit()
    
send_mail('241949382@qq.com',"hahaha")

posted @ 2021-08-07 09:56  wztshine  阅读(94)  评论(0编辑  收藏  举报