Created
May 8, 2024 14:50
-
-
Save documentprocessing/07c7228cff9c01a091199bf1bcabbf89 to your computer and use it in GitHub Desktop.
Extract attachments from MSG file in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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