Created
October 4, 2019 17:14
-
-
Save GitterDoneScott/834764ccc67fa5a4c4b0acc10cd31f62 to your computer and use it in GitHub Desktop.
Save (export) all messages in Outlook inbox as .msg files
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 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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment