python发送邮件

Posted taotao12

tags:

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

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


#qq邮箱smtp服务器
host_server = ‘smtp.qq.com‘
#sender_qq为发件人的qq号码
sender_qq = [email protected]#pwd为qq邮箱的授权码
pwd = ‘****kenbb***‘ ## xh**********bdc
#发件人的邮箱
sender_qq_mail = [email protected]#收件人邮箱
receiver = [email protected]#邮件的正文内容
mail_content = ‘你好,这是使用python登录qq邮箱发邮件的测试‘
#邮件标题
mail_title = ‘Maxsu的邮件‘

#ssl登录
smtp = SMTP_SSL(host_server)
#set_debuglevel()是用来调试的。参数值为1表示开启调试模式,参数值为0关闭调试模式
smtp.set_debuglevel(1)
smtp.ehlo(host_server)
smtp.login(sender_qq, pwd)

msg = MIMEText(mail_content, "plain", ‘utf-8‘)
msg["Subject"] = Header(mail_title, ‘utf-8‘)
msg["From"] = sender_qq_mail
msg["To"] = receiver
smtp.sendmail(sender_qq_mail, receiver, msg.as_string())
smtp.quit()

以上是关于python发送邮件的主要内容,如果未能解决你的问题,请参考以下文章

超实用的php代码片段

Javascript - 使用 HTML 片段通过电子邮件发送 JSON 输出

Github 大牛封装 Python 代码,实现自动发送邮件只需三行代码

C#和ASP.NET通过Gmail账户发送邮件的代码

python笔记- 发送邮件

实现Python代码发送邮件