zoukankan      html  css  js  c++  java
  • 发送HTML格式邮件.py

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

    # 第三方 SMTP 服务
    # 设置服务器
    mail_host = "smtp.qq.com"

    # 用户名
    mail_user = "1320685524@qq.com"

    #获取授权码
    mail_pass="mpaocydzpzfjidge"

    # 发件人账号
    sender = '1320685524@qq.com'

    # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
    receivers = ['1320685524@qq.com']

    send_content = """
    <h1>天不生我李淳罡</h1>
    <h1>剑道万古如长夜</h1>
    <p>小二上酒</p>
    <img src="https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=858168512,2130327819&fm=85&s=2E4020DF1CD035FBDC9D940A0300F0F3">
    <div>阅读请&nbsp;<a href="https://www.37zw.net/0/761/">点我,点我</a></div>
    """

    # 第一个参数为邮件内容,第二个设置网页格式,第三个设置编码
    message = MIMEText(send_content, 'html', 'utf-8')

    # 发件人
    message['From'] = Header("我是发件人", 'utf-8')

    # 收件人
    message['To'] = Header("我是收件人", 'utf-8')

    subject = '雪中悍刀行'
    message['Subject'] = Header(subject, 'utf-8')

    try:
    smtpObj = smtplib.SMTP()
    # 25 为 SMTP 端口号
    smtpObj.connect(mail_host, 25)
    smtpObj.login(mail_user, mail_pass)
    smtpObj.sendmail(sender, receivers, message.as_string())
    print("邮件发送成功")
    except smtplib.SMTPException:
    print("Error: 无法发送邮件")
  • 相关阅读:
    [JSOI2007][BZOJ1031] 字符加密Cipher|后缀数组
    leetcode Flatten Binary Tree to Linked List
    leetcode Pascal's Triangle
    leetcode Triangle
    leetcode Valid Palindrome
    leetcode Word Ladder
    leetcode Longest Consecutive Sequence
    leetcode Sum Root to Leaf Numbers
    leetcode Clone Graph
    leetcode Evaluate Reverse Polish Notation
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12231709.html
Copyright © 2011-2022 走看看