コード例 #1
0
ファイル: utils.py プロジェクト: ion-channel/security_monkey
def send_email(subject=None, recipients=[], html=""):
    """
    Given a message, will send that message over SES or SMTP, depending upon how the app is configured.
    """
    plain_txt_email = "Please view in a mail client that supports HTML."
    if app.config.get('EMAILS_USE_SMTP'):
        try:
            with app.app_context():
                msg = Message(subject, recipients=recipients)
                msg.body = plain_txt_email
                msg.html = html
                mail.send(msg)
            app.logger.debug("Emailed {} - {} ".format(recipients, subject))
        except Exception, e:
            m = "Failed to send failure message with subject: {}\n{} {}".format(subject, Exception, e)
            app.logger.warn(m)
            app.logger.warn(traceback.format_exc())
コード例 #2
0
def send_email(subject=None, recipients=[], html=""):
    """
    Given a message, will send that message over SES or SMTP, depending upon how the app is configured.
    """
    plain_txt_email = "Please view in a mail client that supports HTML."
    if app.config.get('EMAILS_USE_SMTP'):
        try:
            with app.app_context():
                msg = Message(subject, recipients=recipients)
                msg.body = plain_txt_email
                msg.html = html
                mail.send(msg)
            app.logger.debug("Emailed {} - {} ".format(recipients, subject))
        except Exception, e:
            m = "Failed to send failure message with subject: {}\n{} {}".format(subject, Exception, e)
            app.logger.warn(m)
            app.logger.warn(traceback.format_exc())
コード例 #3
0
def send_email(subject=None, recipients=None, html=""):
    """
    Given a message, will send that message over SES or SMTP, depending upon how the app is configured.
    """
    recipients = recipients if recipients else []
    plain_txt_email = "Please view in a mail client that supports HTML."
    if app.config.get('EMAILS_USE_SMTP'):
        try:
            with app.app_context():
                msg = Message(subject, recipients=recipients)
                msg.body = plain_txt_email
                msg.html = html
                mail.send(msg)
            app.logger.debug("Emailed {} - {} ".format(recipients, subject))
        except Exception as e:
            m = "Failed to send failure message with subject: {}\n{} {}".format(
                subject, Exception, e)
            app.logger.warn(m)
            app.logger.warn(traceback.format_exc())

    else:
        if recipients:
            try:
                ses = boto3.client("ses",
                                   region_name=app.config.get(
                                       'SES_REGION', AWS_DEFAULT_REGION))
                ses.send_email(Source=app.config['MAIL_DEFAULT_SENDER'],
                               Destination={"ToAddresses": recipients},
                               Message={
                                   "Subject": {
                                       "Data": subject
                                   },
                                   "Body": {
                                       "Html": {
                                           "Data": html
                                       }
                                   }
                               })

            except Exception as e:
                m = "Failed to send failure message with subject: {}\n{} {}".format(
                    subject, Exception, e)
                app.logger.warn(m)
                app.logger.warn(traceback.format_exc())
コード例 #4
0
ファイル: util.py プロジェクト: zion0425/security_monkey
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
コード例 #5
0
ファイル: util.py プロジェクト: DataDog/security_monkey
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)