#NEWLINE# def send( address , subject , template_name , context ) : #NEWLINE# #INDENT# if is_test_email ( address ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# templateLoader = jinja2 . FileSystemLoader ( searchpath = 'totalimpactwebapp/templates' ) #NEWLINE# templateEnv = jinja2 . Environment ( loader = templateLoader ) #NEWLINE# html_template = templateEnv . get_template ( ( template_name + '.html' ) ) #NEWLINE# html_to_send = html_template . render ( context ) #NEWLINE# mailer = mandrill . Mandrill ( os . getenv ( 'MANDRILL_APIKEY' ) ) #NEWLINE# addressee = { #NEWLINE# #INDENT# 'email' : address , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# addressee [ 'name' ] = context [ 'name' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# msg = { #NEWLINE# #INDENT# 'html' : html_to_send , #NEWLINE# 'subject' : subject , #NEWLINE# 'from_email' : 'team@impactstory.org' , #NEWLINE# 'from_name' : 'The Impactstory team' , #NEWLINE# 'to' : [ addressee ] , #NEWLINE# 'track_opens' : True , #NEWLINE# 'track_clicks' : True , #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# msg [ 'tags' ] = address [ 'tags' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# mailer . messages . send ( msg ) #NEWLINE# logger . info ( ( 'Sent an email to ' + address ) ) #NEWLINE# return msg