simply decode each line to normal string as it is printedlike our pop mail script didor concatenate the line strings returned by retr or top adding newline betweenany of the following will suffice for an open pop server objectinfomsgoct connection retr( fetch first email in mailbox for in msgprint( decode()four ways to display message lines print( '\njoin(msgdecode() [print( decode()for in msgx list(map(printmap(bytes decodemsg))parsing email text to extract headers and components is more complexespecially for mails with attached and possibly encoded partssuch as images as we'll see later in this the standard library' email package can parse the mail' full or headers text after it has been fetched with poplib (or imaplibsee the python library manual for details on other pop module tools as of python there is also pop _ssl class in the poplib module that connects to the server over an ssl-encrypted socket on port by default (the standard port for pop over sslit provides an identical interfacebut it uses secure sockets for the conversation where supported by servers smtpsending email there is proverb in hackerdom that states that every useful computer program eventually grows complex enough to send email whether such wisdom rings true or not in practicethe ability to automatically initiate email from within program is powerful tool for instancetest systems can automatically email failure reportsuser interface programs can ship purchase orders to suppliers by emailand so on moreovera portable python mail script could be used to send messages from any computer in the world with python and an internet connection that supports standard email protocols freedom from dependence on mail programs like outlook is an attractive feature if you happen to make your living traveling around teaching python on all sorts of computers luckilysending email from within python script is just as easy as reading it in factthere are at least four ways to do socalling os popen to launch command-line mail program on some systemsyou can send email from script with call of the formos popen('mail - "xxxa@ '' 'write(textas we saw earlier in the bookthe popen tool runs the command-line string passed to its first argumentand returns file-like object connected to it if we use an open mode of wwe are connected to the command' standard input stream--herewe write the text of the new mail message to the standard unix mail command-line client-side scripting