# -*- coding: utf-8 -*-
"""
Created on Wed Aug 15 17:44:33 2018
@author: cp
"""
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
from email.header import Header
import smtplib
import pandas as pd
import sys
def create_email(email_from,email_to,email_Subject,email_text,img_text,annex_path,annex_name,pic_path,pic_name):
message = MIMEMultipart('mixed')
#添加正文内容
text = img_text + email_text
message.attach(MIMEText(text,"html","utf-8"))
message["From"] = Header(email_from,"utf-8")
message["To"] = Header(email_to,"utf-8")
message["Subject"] = Header(email_Subject,"utf-8")
#添加文件附件
att1 = MIMEText(open(annex_path,"rb").read(),"base64","utf-8")
att1["Content-Type"] = "application/octet-stream"
att1["Content-Disposition"] = "attachment;filename=" + annex_name
message.attach(att1)
#添加图片
att2 = MIMEImage(open(pic_path,'rb').read())
att2.add_header('Co
python 自动发送邮件报表,正文插入图片,带附件
最新推荐文章于 2025-06-19 07:51:34 发布