smtplib for sending email the email module package for parsing email and constructing email these modules are relatedfor nontrivial messageswe typically use email to parse mail text which has been fetched with poplib and use email to compose mail text to be sent with smtplib the email package also handles tasks such as address parsingdate and time formattingattachment formatting and extractionand encoding and decoding of email content ( ,guuencodebase additional modules handle more specific tasks ( mimetypes to map filenames to and from content typesin the next few sectionswe explore the pop and smtp interfaces for fetching and sending email from and to serversand the email package interfaces for parsing and composing email message text other email interfaces in python are analogous and are documented in the python library reference manual ss unicode in python and email tools in the prior sections of this we studied how unicode encodings can impact scripts using python' ftplib ftp tools in some depthbecause it illustrates the implications of python ' unicode string model for real-world programming in shortall binary mode transfers should open local output and input files in binary mode (modes wb and rbtext-mode downloads should open local output files in text mode with explicit encoding names (mode wwith an encoding argument that defaults to latin within ftplib itselftext-mode uploads should open local input files in binary mode (mode rbthe prior sections describe why these rules are in force the last two points here differ for scripts written originally for python as you might expectgiven that the underlying sockets transfer byte strings todaythe email story is somewhat convoluted for unicode in python as well as brief previewfetching the poplib module returns fetched email text in bytes string form command text sent to the server is encoded per utf internallybut replies are returned as raw binary bytes and not decoded into str text ss imapor internet message access protocolwas designed as an alternative to popbut it is still not as widely available todayand so it is not presented in this text for instancemajor commercial providers used for this book' examples provide only pop (or web-basedaccess to email see the python library manual for imap server interface details python used to have rfc module as wellbut it' been subsumed by the email package in client-side scripting