Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save documentprocessing/07c7228cff9c01a091199bf1bcabbf89 to your computer and use it in GitHub Desktop.
Save documentprocessing/07c7228cff9c01a091199bf1bcabbf89 to your computer and use it in GitHub Desktop.
Extract attachments from MSG file in Python
import extract_msg
# Specify the path to your .msg file
msg_file_path = 'path/to/your/file.msg'
# Specify the directory where attachments should be saved
save_directory = 'path/to/save/attachments/'
# Open the MSG file
with extract_msg.openMsg(msg_file_path) as msg:
# Loop through attachments
for attachment in msg.attachments:
# Define the path to save the attachment
file_path = save_directory + attachment.longFilename
# Save the attachment
attachment.save(customPath=file_path)
print(f'Saved attachment to {file_path}')
# Close the MSG file
msg.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment