编程语言
首页 > 编程语言> > python3 smtplib

python3 smtplib

作者:互联网

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

#smtp服务

mail_host = "smtp.qq.com"
mail_user = "111111111@qq.com"
mail_pass = "11111111"

sender = '111111111@qq.com'
receivers = ['222222222@qq.com']

message = MIMEText('邮件发送测试。。。','plain','utf-8')
message['From'] = Header("python学习",'utf-8')
message['TO'] = Header("测试",'utf-8')

subject = 'Python SMTP 邮件测试'
message['Subject'] = Header(subject,'utf-8')

try:
server = smtplib.SMTP()
server.connect(mail_host,25)
server.login(mail_user,mail_pass)
server.sendmail(sender,receivers,message.as_string())
print("send mail successful")
# except Exception as e:
except smtplib.SMTPException as e:
print("Error;send mail fail")
print(e)

标签:qq,utf,server,Header,mail,smtplib,message,python3
来源: https://www.cnblogs.com/gaoyanbing/p/12710646.html