How to connect python with outlook to Automate the report.

Опубликовано: 16 Октябрь 2024
на канале: ExcelVBA Expert
36
8

HI All,

In this video I have told about how we can work with Python with outlook by attaching attachment and Display the same on screen these things we have done in just few line of PYTHON Code.

If you thing still something needs to be done please let me know on below mail

Email ID : [email protected]

Python Code

import pandas as pd
import os
import win32com.client as win32com
path='C:/Users/computers/Desktop/python/Data/'
data=[]
for file in os.listdir(path):
if file.endswith('.xlsx'):
df=pd.read_excel(os.path.join(path,file))
df['Source']=file
df1=pd.DataFrame(df)
data=df1.append(data,ignore_index=True)
data.to_excel('C:/Users/computers/Desktop/python/Masterdata.xlsx')

outlook=win32com.Dispatch('outlook.Application')
mail=outlook.CreateItem(0)
mail.To="[email protected]"
mail.Subject='Masterdata'
mail.HTMLBody='br HI ALL please find the attached data as requested /br'
attachment=mail.Attachments.Add('C:/Users/computers/Desktop/python/Masterdata.xlsx')
mail.Display(True)