-1

this is my actula code :

import poplib, sys, re, threading, time, Queue
from email import parser

    Mailbox = poplib.POP3(pop3, '110')
    Mailbox.user(username)
    Mailbox.pass_(password)
    numMessages = len(Mailbox.list()[1])
    for i in range(numMessages):
            fullemail = ''
            fullemail = '\n'.join([msg for msg in Mailbox.retr(i+1)[1]])
            msg = parser.Parser().parsestr(fullemail)
            for part in msg.walk():
                    print part.get_payload(decode=True)

print part.get_payload(decode=True) print body of email, how i can print header of email ?

kingcope
  • 1,121
  • 4
  • 19
  • 36
  • You are not showing your imports but if you are using the Python `email` library, the currently second example on https://docs.python.org/3.4/library/email-examples.html shows you how. – tripleee Dec 08 '17 at 11:07
  • Possible duplicate of [Extract just email headers in python](https://stackoverflow.com/questions/8424317/extract-just-email-headers-in-python) – tripleee Dec 08 '17 at 11:07
  • If you think "the body" is well-defined, perhaps your understanding of email isn't yet very deep. – tripleee Dec 08 '17 at 11:08

1 Answers1

0

the method items() of email.message.Message/email.message.EmailMessage object may be useful:

for t in msg.items():
    print(t)

t is a tuple like this (key,value).

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34
C.K.
  • 1,409
  • 10
  • 20