我的報告目錄
具體解釋在代碼中有詳細注釋
import win32com.client as win32
import datetime, os
addressee = 'test01@qq.com'+';'+'test02@jd.com'#收件人郵箱列表
cc = 'test02@163.com'+';'+'test03@alibaba.com'#抄送人郵件列表
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#收件人
mail.CC = 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