the second edition of this book used handful of standard library modules (rfc stringioand moreto parse the contents of messagesand simple text processing to compose them additionallythat edition included section on extracting and decoding attached parts of message using modules such as mhlibmimetoolsand base in the third editionthose tools were still availablebut werefranklya bit clumsy and error-prone parsing attachments from messagesfor examplewas trickyand composing even basic messages was tedious (in factan early printing of the prior edition contained potential bugbecause it omitted one \ character in string formatting operationadding attachments to sent messages wasn' even attempteddue to the complexity of the formatting involved most of these tools are gone completely in python as write this fourth editionpartly because of their complexityand partly because they've been made obsolete luckilythings are much simpler today after the second editionpython sprouted new email package-- powerful collection of tools that automate most of the work behind parsing and composing email messages this module gives us an object-based message interface and handles all the textual message structure detailsboth analyzing and creating it not only does this eliminate whole class of potential bugsit also promotes more advanced mail processing things like attachmentsfor instancebecome accessible to mere mortals (and authors with limited book real estatein factan entire original section on manual attachment parsing and decoding was deleted in the third edition--it' essentially automatic with email the new package parses and constructs headers and attachmentsgenerates correct email textdecodes and encodes base quoted-printableand uuencoded dataand much more we won' cover the email package in its entirety in this bookit is well documented in python' library manual our goal here is to explore some example usage codewhich you can study in conjunction with the manuals but to help get you startedlet' begin with quick overview in nutshellthe email package is based around the message object it providesparsing mail mail' full textfetched from poplib or imaplibis parsed into new message objectwith an api for accessing its components in the objectmail headers become dictionary-like keysand components become "payloadthat can be walked with generator interface (more on payloads in momentcreating mail new mails are composed by creating new message objectusing an api to attach headers and partsand asking the object for its print representation-- correctly formatted mail message textready to be passed to the smtplib module for delivery headers are added by key assignment and attachments by method calls emailparsing and composing mail content