-
-
Save garymanley/48e878dfd6a18ef99ea58b4dd563a676 to your computer and use it in GitHub Desktop.
Outlook Inbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from win32com.client import Dispatch | |
import getpass | |
import datetime | |
######################################## | |
## Connect to Outlook inbox | |
######################################### | |
outlook = Dispatch("Outlook.Application").GetNamespace("MAPI") | |
# "6" refers to the index of a folder. 6 is the inbox | |
inbox = outlook.GetDefaultFolder("6") | |
### all inbox for today after 7am | |
all_inbox = inbox.Items.restrict("[ReceivedTime] > '"+datetime.datetime.today().strftime('%d/%m/%Y')+" 07:00 AM'") | |
################## | |
## Loop through e-mails and attachments | |
################## | |
for msg in all_inbox: | |
## prints subject | |
print(msg.Subject) | |
for att in msg.Attachments: | |
### prints file name | |
print(att.FileName) | |
## saves file | |
att.SaveAsFile('C:\\Users\\garym\\Documents\\PyWinAutoBlog\\'+att.FileName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment