My objective is to parse email body from outlook and store it in pandas dataframe thenusing regex get specific values from that dataframe and insert it using oracle database. i am done with regex and oracle script but not able to add outlook emails as dataframe. Can anyone please correct me ? Below is the script
import win32com.client
import pandas as pd
from bs4 import BeautifulSoup
from pprint import pprint
from datetime import datetime, timedelta
outlook = win32com.client.gencache.EnsureDispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")
inbox = mapi.Folders['rahul.vaidya@xyz.com'].Folders['Inbox'].Folders['Important']
Mail_Messages = inbox.Items
Mail_Messages = Mail_Messages.Restrict("[Subject] = 'SGPSBSH Index Level*'")
received_dt = datetime.now() - timedelta(days=1)
for mail in Mail_Messages:
receivedtime = mail.ReceivedTime.strftime('%Y-%m-%d %H:%M:%S')
body = mail.HTMLBody
html_body = BeautifulSoup(body, "lxml")
print(Mail_Messages.body)
SAMPLE EMAIL
