Reputation: 1134
i am working on a project where i have to read specific outlook email on daily basis.
I receive the certain outlook email on daily basis which looks like a table with the subject : Creation Report - 30/04/2018(these dates change daily)
These are the codes i have found on google:
import win32com.client
import os
outlook=win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox=outlook.GetDefaultFolder(6) #Inbox default index value is 6
message=inbox.Items
message2=message.GetLast()
subject=message2.Subject("XID Creation Report")
body=message2.body
date=message2.senton.date()
sender=message2.Sender
attachments=message2.Attachments
print(subject)
print(body)
print(sender)
print(attachments.count)
print(date)
can someone please help on this? Since i dont have much experience in outlook scraping , how can i scrape this subject email from outlook and save it into excel/csv
since body is case sensitive, i cant show it but it is a table.
Upvotes: 1
Views: 4663
Reputation: 1134
I found the answer on my own:
it is simple i am posting my answer here:
import win32com.client
import os
outlook=win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox=outlook.GetDefaultFolder(6) #Inbox default index value is 6
message=inbox.Items
message2=message.GetLast()
subject=message2.Subject
body=message2.body
date=message2.senton.date()
sender=message2.Sender
attachments=message2.Attachments
for m in message:
if m.Subject=="Your-subject-here":# here in my requirement i will change the dates
print(m.body)
it will print your body
Upvotes: 1