+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2019-07(7)

2019-08(96)

2019-09(90)

2019-10(11)

2019-11(6)

python发送邮件模板

发布于2020-10-17 20:58     阅读(578)     评论(0)     点赞(22)     收藏(5)


0

1

2

3

4

5

6

7

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

#基本信息设定为变量
from_addr = 'xxx@163.com'
to_addrs = ['xxx@163.com','xxx@163.com']
password = 'YWBHDEGTURETAGZH'
smtp_server = 'smtp.163.com'
text = 'my email send to xxx'

server = smtplib.SMTP()
server.connect(smtp_server,25)

#创建一个带附件的实例
msg = MIMEMultipart()
msg['From'] = Header(from_addr)
msg['To'] = Header('%s' % to_addrs)
msg['Subject'] = Header('Email send to xxx')

#邮件正文内容
msg.attach(MIMEText(text,'plain','utf-8'))

#构造附件1,传送python_test.txt文件
att = MIMEText(open("G:\Studing\Practice\p\9.send email\python_test.txt").read(),'plain')
att['Content_Disposition'] = 'attachment;filename = "python_test"'
msg.attach(att)

#发送邮件
server.login(from_addr,password)
server.sendmail(from_addr,to_addrs,msg.as_string())
print('Email sent successfully!')
server.quit()

原文链接:https://blog.csdn.net/adamlay/article/details/109073448

0

1

2

3

4

5

6

7

8



所属网站分类: 技术文章 > 博客

作者:大侠

链接: https://www.pythonheidong.com/blog/article/594627/368c4ff45becd45513b0/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

22 0
收藏该文
已收藏

评论内容:(最多支持255个字符)