Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  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")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement