I am using python 3.6.1 and I want to read in email files (.eml) for processing. I am using the emaildata 0.3.4 package, however whenever I try to import the Text class as in the documentation, I get the module errors:
import email
from email.text import Text
>>> ModuleNotFoundError: No module named 'cStringIO'
When I tried to correct using this update, I get the next error relating to mimetools
>>> ModuleNotFoundError: No module named 'mimetools'
Is it possible to use emaildata 0.3.4 with python 3.6 to parse .eml files? Or are there any other packages I can use to parse .eml files? Thanks
Using the email package, we can read in the .eml files. Then, use the
BytesParser
library to parse the file. Finally, use aplain
preference (for plain text) with theget_body()
method, andget_content()
method to get the raw text of the email.Granted, this is a simplified example - no mention of HTML or attachments. But it gets done essentially what the question asks and what I want to do.
Here is how you would iterate over several emails and save each as a plain text file: