<commit_before>#!/usr/bin/env python
"""
This implements a notification system via email
"""
import json
import smtplib
from email.mime.text import MIMEText

from flask import render_template
from flask_mail import Mail, Message
mail = Mail()

from . import app

def send_mail(subject, recipient, template, **context):
    """Send an email via the Flask-Mail extension.

    :param subject: Email subject
    :param recipient: Email recipient
    :param template: The name of the email template
    :param context: The context to render the template with
    """
    msg = Message(subject, sender=app.config.get('MAIL_USERNAME'), recipients=[recipient])

    ctx = ('email', template)
    msg.html = render_template('%s/%s.html' % ctx, **context)
    mail.send(msg)


# note this requires a secrets file to work
required = ['sender_email', 'sender_pass', 'sender_name', 'target_email']<commit_msg>Blanket error handling on emails sent<commit_after>#!/usr/bin/env python
"""
This implements a notification system via email
"""
import json
import smtplib
from email.mime.text import MIMEText

from flask import render_template
from flask_mail import Mail, Message
mail = Mail()

from . import app

def send_mail(subject, recipient, template, **context):
    """Send an email via the Flask-Mail extension.

    :param subject: Email subject
    :param recipient: Email recipient
    :param template: The name of the email template
    :param context: The context to render the template with
    """
    msg = Message(subject, sender=app.config.get('MAIL_USERNAME'), recipients=[recipient])

    ctx = ('email', template)
    msg.html = render_template('%s/%s.html' % ctx, **context)
    try:
        mail.send(msg)
    except Exception as e:
        log.error(u"{} sending {} email to {}: {}".format(e.__class__.__name__, template, email, e))
        return False
    else:
        return True

# note this requires a secrets file to work
required = ['sender_email', 'sender_pass', 'sender_name', 'target_email']
{'fraction_non_alphanumeric': 0.11000497760079642, 'fraction_numerical': 0.0, 'mean_word_length': 4.062972292191436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5152231', 'n_tokens_mistral': 578, 'n_tokens_neox': 566, 'n_words': 208}