简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM