SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from win32com.client import Dispatch
  2. import re
  3.  
  4. outlook = Dispatch("Outlook.Application").GetNamespace("MAPI")
  5. inbox = outlook.GetDefaultFolder("6")
  6. all_inbox = inbox.Items
  7.  
  8. for message in all_inbox:
  9.     try:
  10.         name = str(message.subject)
  11.         #to eliminate any special characters in the name
  12.         name = re.sub('[^A-Za-z0-9\s\-]+', '', name)+'.msg'
  13.         message.SaveAs('C:\\tmp\\attachments'+'\\'+name)
  14.         print("SUCCESSFUL","Message Saved")
  15.     except:
  16.         print("ERROR","Message failed to save")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top