我的报告目录
具体解释在代码中有详细注释
import win32com.client as win32import datetime, osaddressee = 'test01@'+';'+'test02@'#收件人邮箱列表cc = 'test02@'+';'+'test03@'#抄送人邮件列表mail_path = os.path.join(r'C:\Users\songlihui\PycharmProjects\test001keshanchu', 'result', 'report.html')#获取测试报告路径class send_email():def outlook(self):olook = win32.Dispatch("outlook.Application")#固定写法mail = olook.CreateItem(win32.constants.olMailItem)#固定写法mail.To = addressee#收件人 = cc#抄送人# mail.Recipients.Add(addressee)mail.Subject = str(datetime.datetime.now())[0:19]+'XXX反馈报告'#邮件主题mail.Attachments.Add(mail_path, 1, 1, "myFile")read = open(mail_path, encoding='utf-8')#打开需要发送的测试报告附件文件content = read.read()#读取测试报告文件中的内容read.close()mail.Body = content#将从报告中读取的内容,作为邮件正文中的内容mail.Send()#发送if __name__ == '__main__':send_email().outlook()print("send email ok!!!!!!!!!!")
可参考https://win32com.goermezer.de/microsoft/ms-office/send-email-with-outlook-and-python.html