How to save Emails of day from Outlook into a folder using python?


I have been looking for a way to save all emails in the outlook of a particular day or from the start of the day to the time I run my program to my local folder using python. Is there any way we can do this?

---------------Answer---------------

Something along these lines, I believe, would be an excellent starting point:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem(r"C:\test_msg.msg")

print msg.SenderName
print msg.SenderEmailAddress
print msg.SentOn
print msg.To
print msg.CC
print msg.BCC
print msg.Subject
print msg.Body

count_attachments = msg.Attachments.Count
if count_attachments > 0:
    for item in range(count_attachments):
        print msg.Attachments.Item(item + 1).Filename

del outlook, msg

snippet of code comes from another thread see below

Refer to Brent Edwards's answer for more details.

Note: If you won't use Outlook client you could do as follow: https://stackoverflow.com/a/49681576/9814037


Previous : What is a NullReferenceException, and how do I fix it?
Next : looking for object with certain local variable in an array list