#!/usr/bin/python
# -*- coding: UTF-8 -*
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
from_addr = "xxxx@xxxx.com.cn"
pwd = "Aaxxxxxxxx"
to_addr = ['xxxx@xxxx.com.cn,xxxx@xxxx.com.cn,xxxx@xxxx.com.cn,xxxx@xxxx.com.cn']
def send_enclosure():
# 2.创建实例对象,设置主题等信息
msg = MIMEMultipart()
msg["Subject"] = "代码行数统计结果"
msg["From"] = from_addr
msg["To"] = ','.join(to_addr)
# 邮件内容(按每个部分)
part1 = MIMEText("附件压缩包是前端、后端、大数据的代码行数统计结果")
msg.attach(part1)
# 添加压缩包附件
part2 = MIMEApplication(open('20200106-代码行数统计结果.zip', 'rb').read())
part2.add_header('Content-Disposition', 'attachment', filename="20200106-代码行数统计结果.zip")
msg.attach(part2)
# 3.连接smtp服务器,登录服务器并发送文本
smtp_server = "xxxx.xxxx.com.cn"
server = smtplib.SMTP(smtp_server,587)
server.starttls()
server.login(from_addr,pwd)
server.sendmail(from_addr,msg['To'].split(','),msg.as_string()) # as_string()把MIMEText变成一个str
server.close()
if __name__ == '__main__':
send_enclosure()
python 发送带附件邮件
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 之前写过用标准库使用Python Smtplib 和email发送邮件,感觉很繁琐,久了不用之后便忘记了。前几天看...
- from email.header import Headerfrom email.mime.text impor...