Skip to content

Instantly share code, notes, and snippets.

@garymanley
Created December 30, 2017 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garymanley/48e878dfd6a18ef99ea58b4dd563a676 to your computer and use it in GitHub Desktop.
Save garymanley/48e878dfd6a18ef99ea58b4dd563a676 to your computer and use it in GitHub Desktop.
Outlook Inbox
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