Skip to content Skip to sidebar Skip to footer

Extract Just Email Headers In Python

I'm having some issues trying to extract all the email headers in python. I know how to get the ones I'm looking for but I want to save all the headers and I'm not sure how to do t

Solution 1:

Using HeaderParser perhaps:

from email.parser import HeaderParser
parser = HeaderParser()
h = parser.parsestr(email)

print h.keys()

I just noticed you edited your question. You can actually get the same information from what you had without using HeaderParser. e.g. headers.items()will return list of 2-tuples with headers and corresponding values.

Post a Comment for "Extract Just Email Headers In Python"