Building Dynamic HTML Email Content with Python -


i have python dictionary i'd send email in form of 2 column table, have title , 2 column headers, , key,value pair of dictionary populated rows.

<tr> <th colspan="2"> <h3><br>title</h3> </th> </tr> <th> column 1 </th> <th> column 2 </th> "thn dynamic amount of <tr><td>%column1data%</td><td>%column2data%</td></tr> 

the column1 , column2 data key,value pairs associated dictionary.

is there way in simple manner? auotmated email being sent out via cronjob, once day after populating data.

thank all. p.s know nothing markdown :/

p.s.s using python 2.7

basic example: (with templating)

#!/usr/bin/env python  smtplib import smtp              # sending email email.mime.text import mimetext  # constructing messages  jinja2 import environment        # jinja2 templating  template = """ <html> <head> <title>{{ title }}</title> </head> <body>  hello world!.  </body> </html> """  # our html template  # create text/html message rendered template msg = mimetext(     environment().from_string(template).render(         title='hello world!'     ), "html" )  subject = "subject line" sender= "root@localhost" recipient = "root@localhost"  msg['subject'] = subject msg['from'] = sender msg['to'] = recipient  # send message via our own local smtp server. s = smtp('localhost') s.sendmail(sender, [recipient], msg.as_string()) s.quit() 

relevant documentation:

nb: assumes have valid mta on local system.

note also: may in fact want use multipart message when composing email; see examples

update: aside there nice(er) "email sending" libraries out there may of interest you:

i believe these libraries along same lines requests -- smtp humans


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -