mailserver mailconfig smtpservername from input('from'strip(to input('to'strip(tos to split(';'subj input('subj'strip(date email utils formatdate(exsmtp rmi net or import from mailconfig expython-list@python org allow list of recipients curr datetimerfc standard headersfollowed by blank linefollowed by text text ('from% \nto% \ndate% \nsubject% \ \ (fromtodatesubj)print('type message textend with line=[ctrl+ (unix)ctrl+ (windows)]'while trueline sys stdin readline(if not linebreak exit on ctrl- / #if line[: ='from'line '>line servers may escape text +line print('connecting 'server smtplib smtp(mailserverfailed server sendmail(fromtostextserver quit(if failedprint('failed recipients:'failedelseprint('no errors 'print('bye 'connectno log-in step smtplib may raise exceptions toobut let them pass here most of this script is user interface--it inputs the sender' address (from)one or more recipient addresses (toseparated by ";if more than one)and subject line the sending date is picked up from python' standard time modulestandard header lines are formattedand the while loop reads message lines until the user types the end-offile character (ctrl- on windowsctrl- on linuxto be robustbe sure to add blank line between the header lines and the body in the message' textit' required by the smtp protocol and some smtp servers enforce this our script conforms by inserting an empty line with \ \ at the end of the string format expression--one \ to terminate the current line and another for blank linesmtplib expands \ to internet-style \ \ internally prior to transmissionso the short form is fine here later in this we'll format our messages with the python email packagewhich handles such details for us automatically the rest of the script is where all the smtp magic occursto send mail by smtpsimply run these two sorts of callsserver smtplib smtp(mailservermake an instance of the smtp objectpassing in the name of the smtp server that will dispatch the message first if this doesn' throw an exceptionyou're connected client-side scripting