发布时间:2019-09-06 08:57:35编辑:auto阅读(1652)
来源:http://snipperize.todayclose.com/snippet/py/Send-email-with-p_w_upload--53762/
- import smtplib
- from email.MIMEMultipart import MIMEMultipart
- from email.MIMEBase import MIMEBase
- from email.MIMEText import MIMEText
- from email.Utils import COMMASPACE, formatdate
- from email import Encoders
- import os
- def sendMail(to, subject, text, files=[],server="localhost"):
- assert type(to)==list
- assert type(files)==list
- fro = "Expediteur <expediteur@mail.com>"
- msg = MIMEMultipart()
- msg['From'] = fro
- msg['To'] = COMMASPACE.join(to)
- msg['Date'] = formatdate(localtime=True)
- msg['Subject'] = subject
- msg.attach( MIMEText(text) )
- for file in files:
- part = MIMEBase('application', "octet-stream")
- part.set_payload( open(file,"rb").read() )
- Encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'p_w_upload; filename="%s"'
- % os.path.basename(file))
- msg.attach(part)
- smtp = smtplib.SMTP(server)
- smtp.sendmail(fro, to, msg.as_string() )
- smtp.close()
- sendMail(
- ["destination@dest.kio"],
- "hello","cheers",
- ["photo.jpg","memo.sxw"]
- )
上一篇: hadoop安装(3)
下一篇: h3c交换机配置(下)
47863
46424
37314
34760
29332
25990
24945
19967
19564
18050
5806°
6433°
5947°
5975°
7080°
5926°
5963°
6456°
6418°
7798°