Package: mini-postoffice
mini_postofficepython module,  easy way to send email.Class.MiniMailMiniMail is class to create a mail body, is an inherit class from email.message.EmailMessage, which can be sent by smtplib of python, or the class MiniPostMan afterward.chardet is the only extend module, which is to recognize the encoding of file.Methodclass MiniMail(self, from_ = '', to = '', subject ='', gid = 'aipython', prefix = 'mmail')Initialize instancefrom, to, subject:   refer toRFC822, which are mini requirement for email fieldsgid: as part identification for content-id in emailmmail: used in html template, as format idMiniMail.add_text(self, content, encoding = 'utf-8')Add plain text content in emailcontent: string, plain text contentencoding: string, charset of contentMiniMail.add_html(self, html, cids, body = None)Add html to email or an instance of EmailMessagehtml: string, the html contentcids: list or dictionary, resources for html, which made by make_cid_list() or make_cid_dict(), in which are objects with the keys of attachment, maintype, subtype, cid, filename, encoding.body: can be EmailMessage, or payload of emailMiniMail.add_html_auto(self, html, sources, body = None)Easy way to call MiniMail.add_html()html: string, the html template, in which the refer will like mmail_0, mmail is self._prefix, 0 is the index of 			fmt list, e.g. fmt = {'mmail_0' : 'abc', 'mmail_1' : 'def'}, then after html formating, mmail_0 will be 			replaced by abc, mmail_1 will be replaced by def.sources: list or dictionary,  path of resource files which will be referenced in html.body: email.message, can be an instance of EmailMessage, or payload of emailMiniMail.get_encoding(self, b)Get the content encoding, using module chardet to detectb: byte, the content of filereturn: string, name of encodingMiniMail.get_MEMF(self, file)Get mimetype, encoding, opening mode, filename of file pathfile: string, file pathreturn: tuple of string, with minetype, encoding, mode, filenameMiniMail.get_file_encoding(self, file)Get encoding of filefile: string, file pathreturn: string, name of encodingMiniMail.add_attachment(self, files, body = None)Add files as attachment into email or an instance of EmailMessagefiles: list, files to attachbody: email.message, can be an instance of EmailMessage, or payload of emailMiniMail.add_email(self, mail, body = None)Add mail as attachment into email or an instance of EmailMessagemail: email.message or .eml, email to attachMiniMail.make_cid_list(self, files)Prepare files data for other methods, data have bytes of file, maintype, subtype, cid, filename, encodingfiles: list,  list of file pathreturn: list, of cid objectsMiniMail.make_cid_dict(self, files)Prepare files data for other methods, data have bytes of file, maintype, subtype, cid, filename, encodingfiles: list,  list of file pathreturn: dictionary, of cid objectsMiniMail.sorting_cids(self, cids)Soring cids, to make self._embedded type at first in cids, after that other type.cids: list,  or dictionary, data set from cid_list() or cid_dict()return: listMiniMail.set_property(self, property_, value)General method to assign value to inner propertiesproperty_: string, name of propertyvalue: all kind of typesMiniMail.get_property(self, property_)General method to get value of inner propertiesproperty_: string, name of propertyreturn: value of propertyMiniMail.get_addresses(self)Get all email addresses in emailreturn: list, of all addressesMiniMail.get_mail(self)Get total email bodyreturn: EmailMessage, email bodyClass.MiniPostManMiniPostMan fulfills lite function to send email, of which inner core is stmplib, standard module of python.Methodclass MiniPostMan(self, host='', useremail='', pwd=''，debuglevel = 0)Initialization of class, setting required propertieshost: string, the smtp server urlusermail: string, account to login host, email address of sender is okpwd： password of logindebuglevel：set the debug output levelMiniPostMan.email_valid(self, addresses)Validate email addressaddresses: list, with email addressesreturn: booleanMiniPostMan.quick_send(self, receiver, subject='hello', content='')Lite method to send a text emailreceiver: string, email address of receiversubject: string, subject of emailcontent: string, messageMiniPostMan.get_addresses(self, mail)Get all addresses in mailmail: email.message, an instance of email.messagesreturn: list, of all addressesMiniPostMan.send_mail(self, mail, method = 'smtp')Send emailmail: email.message, an instance of email.messagesmethod: string, send method, smtp or sslMiniPostMan.set_property(self, property_, value)General method to assign value to inner propertiesproperty_: string, name of propertyvalue: all kind of typesUsageCreating instance of email, calls MiniMail.Setting fields necessarily, such as 'From', ‘To', calls MiniMail.set_property.Adding contents into the email instance, calls MiniMail.add_text, MiniMail.add_html_auto, MiniMail.add_attachment, MiniMail.add_email, according to perposes.Creating instance of MiniPostman.Setting URL and credential of email server, calls MiniPostman.set_property.Sending mail,  calls MiniPostman.send_mail with the email content getting by calling MiniMail.get_mail.Examplefrommini_postofficeimportMiniPostManfrommini_postofficeimportMiniMail#create an instance of MiniPostManamail=MiniPostMan()amail.set_property('host','smtp.gmailx.com')#smtp serveramail.set_property('user','aipython@gmailx.com')#account of sender for smtp serveramail.set_property('pwd','IqkPjWHFpz3')#password of sender for smp server#create an instance of MiniMailtmail=MiniMail()tmail.set_property('from','aipython@gmailx.com')## tmail.set_property('to', 'datadriver<23817@gmailx.com>,jry<jry@gmailx.com>') #if want to send to many receiverstmail.set_property('to','datadriver<23817@gmailx.com>')#email of receviertmail.set_property('subject','mini postoffice')#subject of email, optional#html templateh='''<html><head></head><body><h3>mini_postoffice</h3><p>a email module, coded in python.</p><img src = 'cid:{mmail_1}'><img src = 'cid:{mmail_0}'></body></html>'''#format html templatecid_list=tmail.make_cid_list(['image.jpg','image1.png'])src=[]forcincid_list:src.append(c['cid'])h=h.format(img1=src[0],img2=src[1])tmail.add_html_auto(h,[])#add html to emailtmail.add_attachment(['image.jpg','excel.xlsx'])#add other attachment, optionalamail.send_mail(tmail.get_mail())#send mailBe aware for the mapping when calladd_html_auto.{mmail_1}will be replaced by 'image1.png', beacuse the index of 'image1.png' in cid_list is1,{mmail_0}will be replaced by 'image.jpg',  because the index is0in cid_list.Illustration of emailReferenceemail— An email and MIME handling package of Pythonsmtplib— SMTP protocol client of Pythonchardet— chardet 3.0.4MIME— from wikipediaRFC1521— multipart/alternative, multipart/mixedRFC2112— multipart/relatedRFC4021— Registration of Mail and MIME Header FieldsRFC2045,RFC2046,RFC2047,RFC2048— Multipurpose Internet Mail Extensions, Part one to Part fourRFC5321— Simple Mail Transfer ProtocolRFC5322— Internet Message FormatRFC2821,RFC6532,RFC6657,RFC5233