[Python] Extract just email headers in python

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    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 that.

    I have it loaded into a email object

    import email
    f = open(kwargs['opt_emailfile'])
    msg = email.message_from_file(f)
    f.close()


    So I can get

    msg['To']
    msg['From']


    But I want all the headers

    Continue reading...

Compartilhe esta Página