如何使用win32com在Python电子邮件中插入Pandas变量

问题描述 投票:-1回答:1

嗨,我正在使用以下代码以及Pandas和Numpy

import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'Test'
mail.Body = 'Message body'
mail.HTMLBody = '<html>............................</html>'
 #this field is optional

# To attach a file to the email (optional):
#attachment  = "Path to the attachment"
#mail.Attachments.Add(attachment)

mail.Send()

在html体中我想使用pandas中的一些值,如df.shape [0]或df ['column']。max()或甚至variable1 = df ['column']。max()

我如何在上面的代码中实现这一点,我打算在HTML消息中使用Pandas中的值到Outlook。

python pandas outlook win32com
1个回答
1
投票

电子邮件的正文是一个字符串,因此您只需使用format并替换任何变量,例如:

mail.HTMLBody = '<html>........variable1 is: {v}....</html>'.format(v=variable1)  
© www.soinside.com 2019 - 2024. All rights reserved.