Skip to content

Instantly share code, notes, and snippets.

@JasonSpine
Created January 23, 2017 09:08
Show Gist options
  • Save JasonSpine/647cd0f7776d326868cb1fedabaed74b to your computer and use it in GitHub Desktop.
Save JasonSpine/647cd0f7776d326868cb1fedabaed74b to your computer and use it in GitHub Desktop.
Extract all attachments of *.eml files
import email
import os
path = './'
listing = os.listdir(path)
for fle in listing:
if str.lower(fle[-3:])=="eml":
msg = email.message_from_file(open(fle))
attachments=msg.get_payload()
for attachment in attachments:
try:
fnam=attachment.get_filename()
f=open(fnam, 'wb').write(attachment.get_payload(decode=True,))
f.close()
except Exception as detail:
#print detail
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment