1

How can I download,save or extract Attachments file from MSG file in python? There is so many Library for extract sender name or ... but for extract msg files not working.

Tomy
  • 225
  • 5
  • 18
  • This is a duplicate of: https://stackoverflow.com/q/26322255/11301900 – AMC Jan 12 '20 at 22:09
  • 3
    Does this answer your question? [Parsing outlook .msg files with python](https://stackoverflow.com/questions/26322255/parsing-outlook-msg-files-with-python) – Ryan M Jan 13 '20 at 01:06

1 Answers1

0

For extract files from MSG files of Outlook use this code:

import win32com.client,os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
msg = outlook.OpenSharedItem('C:/Users/aa/test.msg')
for att in msg.Attachments:
        print(att.FileName)
        print(msg.Attachments.Count)
        att.SaveASFile(os.path.join(save_folder, str(att.FileName))) # save_folder is that folder for save Attachments files  example: C:/Users/aa/extract

and Done!

Tomy
  • 225
  • 5
  • 18
  • can we close the file? I get this error: ""We can't open 'HVB Curves 27-1-2021.msg'. It's possible the file is already open, or you don't have permission" – mas Mar 30 '21 at 23:24