user5298729
user5298729

Reputation: 105

Extract Full Email header using imaplib in Python

I am trying to extract the entire email header using imaplib in Python. At the momment I am using the line below which provides subject, From, To and Date etc but seems to be missing a lot of data compared to when I view the original message in gmail.

  email_header = imapSession.fetch(1, '(RFC822.HEADER)')

I would like to include the full email header with items such as the received locations like below:

Received: from [136.167.40.119] (HELO dc.edu) by fe3.dc.edu (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 61258719 for [email protected]; Mon, 23 Aug 2004 11:40:10 -0400

Is this possible with imaplib?

Thanks in advance

Upvotes: 0

Views: 314

Answers (1)

tripleee
tripleee

Reputation: 189628

RFC822.HEADER should give you the full headers. If you are seeing otherwise, the server is broken. (More likely you are testing with a message which doesn't have the headers you expect.)

Upvotes: 0

Related Questions