概述
展开全部
#coding=utf-8
62616964757a686964616fe58685e5aeb931333337613862'''
create this file
Make it easier to maintain
'''
MailList = {'ablhy' : ['Yeah2015'],
'test' : ['testformail'],
}
def send(text, to, subject, imgpath="no"):
import smtplib
from email.Header import Header
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
from email.Utils import COMMASPACE, formatdate
from email import Encoders
assert type(to)==list
#fro: 发邮件人的Email, server :mail server ..
fro = "xx.xx.xx.xx"
server="xx.xx.xx.xx"
msg = MIMEMultipart()
To = to
msg['From'] = fro
msg['To'] = COMMASPACE.join(To)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = Header(subject, 'utf-8')
#文本内容
msg.attach( MIMEText(text,'html', 'utf-8'))
#附件:两图片
msg.attach(MIMEImage(open("./test.jpg",'rb').read()))
msg.attach(MIMEImage(open("./testpng.png",'rb').read()))
if (imgpath != "no"):
f = open(imgpath, 'rb')
msgImage = MIMEImage(f.read())
f.close()
msgImage.add_header('Content-ID', '')
msg.attach(msgImage);
smtp = smtplib.SMTP(server)
smtp.sendmail(fro, To, msg.as_string() )
smtp.close()
def sendEmail(text, to, subject, imgpath='no'):
if MailList.has_key(to):
send(text, MailList[to], subject, imgpath)
else:
send(text, MailList['test'], subject, imgpath)
#测试
if __name__ == '__main__':
sendEmail('Test', 'ablhy', '删除日志提醒');
最后
以上就是眼睛大白开水为你收集整理的python发邮件图片太长显示不出来_Python 发送多图邮件为什么只显示第一张?的全部内容,希望文章能够帮你解决python发邮件图片太长显示不出来_Python 发送多图邮件为什么只显示第一张?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复