Python 使用Stmp服务使用QQ邮箱给某人发送邮件

Posted 神迹丶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 使用Stmp服务使用QQ邮箱给某人发送邮件相关的知识,希望对你有一定的参考价值。

# coding=utf-8
import smtplib
from email.mime.text import MIMEText

msg_from = \'abcdefghi@qq.com\'  # 发送方邮箱
passwd = \'abcdefghijklmn\'  # 填入发送方邮箱的授权码
msg_to = \'abcdefghi@qq.com\'  # 收件人邮箱

subject = "python邮件测试"  # 主题
content = "这是我使用python smtplib及email模块发送的邮件"     # 正文
msg = MIMEText(content)
msg[\'Subject\'] = subject
msg[\'From\'] = msg_from
msg[\'To\'] = msg_to
try:
    s = smtplib.SMTP_SSL("smtp.qq.com", 465)                    # 邮件服务器及端口号
    s.login(msg_from, passwd)
    s.sendmail(msg_from, msg_to, msg.as_string())
    print("发送成功")
except s.SMTPException:
    print("发送失败")

finally:
    s.quit()

 

以上是关于Python 使用Stmp服务使用QQ邮箱给某人发送邮件的主要内容,如果未能解决你的问题,请参考以下文章