although we can' provide an exhaustive reference herelet' step through simple interactive session to illustrate the fundamentals of email processing to compose the full text of message--to be delivered with smtplibfor instance--make messageassign headers to its keysand set its payload to the message body converting to string yields the mail text this process is substantially simpler and less error-prone than the manual text operations we used earlier in example - to build mail as stringsfrom email message import message message( ['from''jane doe ['to''pp @learning-python comm set_payload('the owls are not what they seem ' str(mprint(sfromjane doe topp @learning-python com the owls are not what they seem parsing message' text--like the kind you obtain with poplib--is similarly simpleand essentially the inversewe get back message object from the textwith keys for headers and payload for the bodys same as in prior interaction 'fromjane doe \ntopp @learning-python com\ \nthe owls are not from email parser import parser parser(parsestr(sx ['from''jane doe get_payload('the owls are not what they seem items([('from''jane doe ')('to''pp @learning-python com')so far this isn' much different from the older and now-defunct rfc modulebut as we'll see in momentthings get more interesting when there is more than one part for simple messages like this onethe message walk generator treats it as single-part mailof type plain textfor part in walk()print( get_content_type()print( get_payload()text/plain the owls are not what they seem client-side scripting