我正在 python 中探索使用带有包含表格内容的正文内容的exchangelib库编写电子邮件。
我已经尝试了在正文内容中添加表格的代码。
import pandas as pd
import numpy as np
from exchangelib import Account, Credentials, Message, Mailbox
dfReport = pd.read_excel("test.xlsx")
FilteredData = dfReport[dfReport["ColumnID"].str.contains('MyCharacter')]
DataTable = pd.pivot_table(FilteredData ,index="Processor",values="TicketID",aggfunc=np.count_nonzero,margins=True)
EmailAdd = 'XXX@YYY.Z'
EmailPass = 'XXXXXX'
MyAccount = Account(EmailAdd,credentials=Credentials(EmailAdd,EmailPass),autodiscover=True)
MyMessage = Message(account=MyAccount, folder=MyAccount.sent,subject='Daily motivation', body=DataTable, to_recipients=[Mailbox(email_address='AAA@BBB.CC')])
MyMessage.send_and_save()
消息正文中应有以下演示:
Name Count
Item 1 53
Item 2 38
Item 3 123
Item 4 175
Item 5 212
但在 Outlook Exchange 电子邮件看起来像这样:
Name
Count
Item 1 53
Item 2 38
Item 3 123
Item 4 175
Item 4 212