Python code to extract single/multiple attachments(.pdf/.png) from .msg file

54 Views Asked by At

I have a master folder containing 10-15 .msg files.

Each file may or maynot have attachments either in pdf or png format.

Is there any python code to extract those attachments .

P.S i already tried pywin32..it is specific to just windows. I am looking to run my code in linux/ubuntu terminal.

1

There are 1 best solutions below

0
Pontis On

This can be done with the package extract_msg as shown below in the form of a MWE (without looping all mail files, without considering overwriting due to duplicate filenames, etcetera).

import extract_msg

with extract_msg.openMsg('Mail.msg') as msg:
    for attm in msg.attachments:
        file = attm.save()