email_helper.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:open-source-feeds 作者: mhfowler 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号