def send_email(to_email, subject, template_path, template_vars, attachment_path=None):
if not ENV_DICT['SEND_EMAIL']:
print '++ sending emails is currently disabled in this environment. Enable SEND_EMAIL to allow email sending'
return
# email address that emails will be sent from
from_email = ENV_DICT['MAIL_DEFAULT_SENDER']
# render HTML from template
page_html = render_template(template_path, **template_vars)
msg = Message(subject=subject,
sender=from_email,
recipients=[to_email],
html=page_html)
if attachment_path:
with open(attachment_path, 'r') as f:
msg.attach("osf-results.json", "text/plain", f.read())
mail.send(msg)
评论列表
文章目录