1. # 发送多种类型的邮件
    2. import smtplib
    3. from email.mime.multipart import MIMEMultipart
    4. from email.mime.text import MIMEText
    5. def postQQ(text, QQ_Code):
    6. """
    7. QQ邮箱发送
    8. :param text: 发送的内容
    9. :param QQ_Code: 接收方邮箱
    10. :return: 返回值为空
    11. """
    12. msg_from = '' # 发送方邮箱
    13. passwd = '' # 就是上面的授权码
    14. to = QQ_Code # 接受方邮箱 格式全称
    15. msg = MIMEMultipart() # 设置邮件内容 # MIMEMultipart类可以放任何内容
    16. # content = str(text)
    17. content = '''
    18. <head><style>::-webkit-scrollbar {width: 6px;height: 5px;}::-webkit-scrollbar-track {background-color: rgba(50, 57, 61, 0.2);border-radius: 2em;}::-webkit-scrollbar-thumb {background-color: #202b33;background-image: -webkit-linear-gradient(45deg, hsla(0, 0%, 100%, 0.4) 25%, transparent 0, transparent 50%, hsla(0, 0%, 100%, .4) 0, hsla(0, 0%, 100%, .4) 75%, transparent 0, transparent);border-radius: 2em;}</style></head><body><div class="email" style="width: 340px; height: 400px; background-color: #cce2dd; margin-top: 50px; margin-left: auto; margin-right: auto;border-radius: 16px; box-shadow: 1px 2px 5px rgb(0,0,0,0.3);position: relative; overflow: hidden;"><img src="https://cdn.jsdelivr.net/gh/Rr210/image@master/hexo/4/0072Vf1pgy1foxlhi4bpsj31kw0w0qs8.jpg" alt="" style="display: block; width: 100%;"><h3 style="background:hsla(249, 13%, 20%, 0.659); border-radius: 10px;width: 80%;height: 40px; line-height: 40px; text-align: center;font-size: 16px; position: absolute;top: 88px;left: 34px;color: #e7dfee;"> 别慌别慌~~这只是一个xx提醒!!</h3><h4 style="position:absolute;top: 45px;right:12px;height: 30px; color: #1f3834;">————来自【xxxx】的提醒:</h4><div readonly="readonly" style="margin:20px auto 0; display: flex; justify-content: center; align-items: center; border-radius:10px; outline:none; padding: 10px; background-color: hsla(220, 12%, 65%, 0.478);resize:none;max-width: 300px;height: 100px;max-height: 100px; box-shadow: 0 0 10px #352c2c3b;border: 1px solid #a0b3d6; font-size: 12px; overflow-wrap: break-word;-webkit-user-modify: read-only">''' + text + '''</div><div style="font-size: 12px;margin:20px 0 0;display: flex; justify-content: center; align-items: center; text-align: center;color:#200f0f;"> <div>©2021 by</div><a style="text-decoration:none; color:#7c4a0d; margin-left: 5px;" href="https://u.mr90.top">Harry</a></div><h6 style="color: #901594;right:10px;bottom:-20px;position: absolute;">by <a href="https://github.com/Rr210/" target="_blank">Harry</a></h6></div></body>
    19. '''
    20. msg.attach(MIMEText(content, 'html', 'utf-8')) # 把内容加进去
    21. msg['Subject'] = "这里是自定义的主题" # 设置邮件主题
    22. msg['From'] = msg_from # 发送方信息
    23. s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 开始发送 通过SSL方式发送,服务器地址和端口
    24. s.login(msg_from, passwd) # 登录邮箱
    25. s.sendmail(msg_from, to, msg.as_string()) # 开始发送
    26. if __name__ == "__main__":
    27. postQQ('', '')