Package: emailbuilder
EMailBuilderSimple HTML e-mail template builder python library. Allows for embedded images and matplotlib charts.Table of ContentsEMailBuilderTable of ContentsInstallationUsageThe EMail Class/ObjectAttributesSubjectSenderReceiver, Copy and Blind CopyStyleMethodsemail.append()email.attach()email.html()email.plain() (W.I.P.)email.message()ComponentsBasic ElementsHeaderParagraphEmbedabblesImageImageRawFigureContainersContainerTo-DoInstallationYou can install the latest release with pip:pipinstallemailbuilderOr build and install the development version yourself:gitclonehttps://github.com/coheleth/emailbuilder&&\pipinstall./emailbuilderUsageImport EmailBuilder:importemailbuilderasebCreate anemailbuilder.EMailobject and append elements to it:# Create eb.EMail object# (see the "EMail class" section for more details)email=eb.EMail("EMail Subject","sender@example.com","receiver@example.com")#  Append components to the eb.EMail object# (see the "Components" section for more details)email.append(eb.Header("Hello World!"))email.append(eb.Paragraph("Lorem ipsum dolor sit amet consectetur"))You can also append matplotlib figures:plt.figure()plt.plot([1,2])plt.title("Example")email.append(eb.Figure(plt.gcf(),"example-figure"))Then, you can send the e-mail via your preferred method. For instance:s=smtplib.SMTP(...)...s.send_message(email.message())s.quit()The EMail Class/ObjectThis object is used for setting the information relating to the e-mail, and provides methods to render the e-mail contents.AttributesSubjectThe e-mail's subject, as a stringSenderThe sender's e-mail, as a stringReceiver, Copy and Blind CopyThe receiver(s)'s e-mail(s), as either a string or a listStyleA dictionary containing the basic style rules for the e-mail.
(More information concerning styling to be added)Methodsemail.append()email.append(component)Appends a component to the end of the e-mailemail.attach()withopen("file.png","rb")asf:email.attach(item=f.read(),type="image",extension="png",cid="my_image",mime=MIMEImage(f.read())# Optional)Adds an attachment to the e-mail.email.html()print(email.html())Returns the e-mail as HTML.email.plain() (W.I.P.)print(email.plain())Returns the e-mail as plain text.email.message()s.send_message(email.message())Returns the e-mail as aEmailMessageobject.ComponentsBelow are the included components in the emailbuilder library.Basic ElementsHeadereb.Header(content:str,style:dict={})An<h1>element, with the text from thecontentparameter.Paragrapheb.Paragraph(content:str,style:dict={})A single paragraph, with the text from thecontentparameter.EmbedabblesImageeb.Image(src:str,alt:str="",cid:str=<filename>,style:dict={})An embedded image, loaded from thesrcpath. Alternative text, used for text-only e-mails is passed through thealtparameter.ImageRaweb.ImageRaw(image:bytes,extension:str,alt:str="",cid:str=<hashedbytes>,style:dict={})An embedded image, loaded as bytes from theimageparameter. An image format must be provided through theextensionparameter.Figureeb.Figure(figure:matplotlibfigure,alt:str,style:dict={},kwargs:dict={})An embedded MatPlotLib figure. Custom arguments for thesavefigfunction can be passed through thekwargsparameter.ContainersContainereb.Container(style:dict={})A<div>element. Items can be appended with theappend(item)method, just like with theEMailobject.To-DoWrite basic usage guideAdd win32com.client outlook supportImprove classes and functions documentationAdd CC and BCCAdd table componentDocumentstyleargumentImprove plain text function