Solved: parse email python

The main problem with parsing email is that it can be a time-consuming process. Email is often formatted in a way that makes it difficult to understand, and it can contain large amounts of text.

import email

msg = email.message_from_string('From: foo@bar.comnSubject: testnntest')

print msg['From']
print msg['Subject']

This code imports the email module, which allows you to parse email messages. It then creates a message object from a string, and prints the “From” and “Subject” headers from the message.


Parsing in Python is the process of turning a string of text into a data structure that can be understood by the Python interpreter. This can involve identifying and extracting specific pieces of information from the text, such as individual words or sentences.

Python provides a variety of built-in parsers for handling different types of text, including regular expressions and lexical analyzers. These tools can be used to parse strings into lists of items, dictionaries of key-value pairs, or other data structures.


Email is a communication protocol used to send messages between computers. Email messages are composed of a header section, body section, and footer section. The header section contains information about the email, such as the sender’s email address and the recipient’s email address. The body section contains the message itself. The footer section contains information about the email, such as when it was sent and how many bytes it is.

Related posts:

Leave a Comment