Exemplo n.º 1
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())
Exemplo n.º 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())
Exemplo n.º 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())
Exemplo n.º 4
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)
Exemplo n.º 5
0
 def __call__(self, *args, **kwargs):
     with app.app_context():
         return TaskBase.__call__(self, *args, **kwargs)