the class is initialized with the hostname of the -mail servera usernameand password to log inimport smtplib import imaplib class emailfacadedef __init__(selfhostusernamepassword)self host host self username username self password password the send_email method formats the -mail address and messageand sends it using smtplib this isn' complicated taskbut it requires quite bit of fiddling to massage the "naturalinput parameters that are passed into the facade to the correct format to enable smtplib to send the messagedef send_email(selfto_emailsubjectmessage)if not "@in self usernamefrom_email "{ }@{ }formatself usernameself hostelsefrom_email self username message ("from{ }\ \ "to{ }\ \ "subject{ }\ \ \ \ { }"formatfrom_emailto_emailsubjectmessagesmtp smtplib smtp(self hostsmtp login(self usernameself passwordsmtp sendmail(from_email[to_email]messagethe if statement at the beginning of the method is catching whether or not the username is the entire "frome-mail address or just the part on the left side of the symboldifferent hosts treat the login details differently finallythe code to get the messages currently in the inbox is ruddy messthe imap protocol is painfully over-engineeredand the imaplib standard library is only thin layer over the protocoldef get_inbox(self)mailbox imaplib imap (self host