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

# 收发人
# sender = '[email protected]'
# password = 'fuck'
sender = '[email protected]'
password = 'fuck'
receivers = ["[email protected]", "[email protected]", "[email protected]"]  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

mail_msg = """
<p>Python 邮件发送测试...</p>
<p><a href="http://www.baidu.com">百度一下你就知道</a></p>
"""
message = MIMEText(mail_msg, 'html', 'utf-8')
message['Subject'] = '开门,劳资是HTML邮件'
message['From'] = sender
message['To'] = ';'.join(receivers)

try:
    # 登录邮件服务器
    # smtpObj = smtplib.SMTP('smtp.163.com', 25)#网易的审核比较严格
    smtpObj = smtplib.SMTP_SSL()
    smtpObj.connect('smtp.qq.com', 465)
    smtpObj.login(sender, password)


    # 发送和退出
    smtpObj.sendmail(sender, receivers, message.as_string())
    smtpObj.quit()
    print("邮件发送成功")

# 处理异常
except smtplib.SMTPException as e:
    print("Error: 无法发送邮件", e)

results matching ""

    No results matching ""