Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from win32com.client import Dispatch
- import re
- outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
- inbox = outlook.GetDefaultFolder("6")
- all_inbox = inbox.Items
- for message in all_inbox:
- try:
- name = str(message.subject)
- #to eliminate any special characters in the name
- name = re.sub('[^A-Za-z0-9\s\-]+', '', name)+'.msg'
- message.SaveAs('C:\\tmp\\attachments'+'\\'+name)
- print("SUCCESSFUL","Message Saved")
- except:
- print("ERROR","Message failed to save")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement