def _send_failure_email(sprinkler, attempts, direction): ses = boto.ses.connection.SESConnection() ses.send_email( source = '*****@*****.**', subject = 'Failed to turn sprinkler {0} {1}'.format(sprinkler.name, direction), body = 'Sorry, I could not manage to control sprinkler {0} after {1} attempts. I was trying to turn it {2}'.format(sprinkler, attempts, direction), to_addresses = '*****@*****.**')
def customer_registered(): """Send an e-mail using SES""" response = None if request.json is None: # Expect application/json request response = Response("", status=415) else: message = dict() try: # If the message has an SNS envelope, extract the inner message if request.json.has_key('TopicArn') and request.json.has_key('Message'): message = json.loads(request.json['Message']) else: message = request.json # Connect to SES and send an e-mail ses = boto.ses.connect_to_region(application.config['AWS_REGION']) ses.send_email(source=application.config['SOURCE_EMAIL_ADDRESS'], subject=SUBJECT, body=BODY % (message['name']), to_addresses=[message['email']]) response = Response("", status=200) except Exception as ex: logging.exception('Error processing message: %s' % request.json) response = Response(ex.message, status=500) return response
def customer_registered(): """Send an e-mail using SES""" response = None if request.json is None: # Expect application/json request response = Response("", status=415) else: message = dict() try: # If the message has an SNS envelope, extract the inner message if request.json.has_key('TopicArn') and request.json.has_key( 'Message'): message = json.loads(request.json['Message']) else: message = request.json # Connect to SES and send an e-mail ses = boto.ses.connect_to_region(application.config['AWS_REGION']) ses.send_email(source=application.config['SOURCE_EMAIL_ADDRESS'], subject=SUBJECT, body=BODY % (message['name']), to_addresses=[message['email']]) response = Response("", status=200) except Exception as ex: logging.exception('Error processing message: %s' % request.json) response = Response(ex.message, status=500) return response
def run_reports(overwrite='false'): """ Run project reports. """ overwrite = (overwrite == 'true') print 'Starting at %s' % timezone.now() updated_reports = [] for project in Project.objects.all(): updated_reports.extend(project.run_reports(overwrite=overwrite)) project.social.refresh() if updated_reports: print 'Sending notification email' email_body = render_to_string('email.txt', {'reports': updated_reports}, '/tmp/email.txt') if app_config.DEPLOYMENT_TARGET: ses = boto.ses.connect_to_region(app_config.SES_REGION) ses.send_email(app_config.EMAIL_SEND_ADDRESS, 'Carebot cares!', email_body, [app_config.EMAIL_NOTIFY_ADDRESS])
def email_subscriptions(xss_uid, url): """ Email all users who are subscribed to assessments. """ email_list = [] notify_jobs = Payload.query.filter_by(id=xss_uid).first() user_notify = User.query.all() # Loop through every User and intersect if the capture is associated with # an assessment they are subscribed to recieve notificaitons for. for user in user_notify: user_subscriptions = [] for assessment in user.assessments: user_subscriptions.append(assessment.id) if len(set(notify_jobs.show_assessment_ids()).intersection(user_subscriptions)) > 0: email_list.append(user.email) import cgi subject = "[Sleepy Puppy] - Capture Recieved From: {}".format(cgi.escape(url, quote=True)) html = "<b>Associated Assessments: </b>{}<br/>".format(cgi.escape(notify_jobs.show_assessment_names(), quote=True)) html += "<b>URL: </b>{}<br/>".format(cgi.escape(url, quote=True)) html += "<b>Parameter: </b>{}<br/>".format(cgi.escape(notify_jobs.parameter or "", quote=True)) html += "<b>Payload: </b>{}<br/>".format(cgi.escape(notify_jobs.payload, quote=True)) html += "<b>Notes: </b>{}<br/>".format(cgi.escape(notify_jobs.notes, quote=True)) html += "https://{}/admin/capture/{}".format(app.config.get("HOSTNAME", "localhost"), notify_jobs.id) # If there are people to email, email them that a capture was recieved if email_list: if app.config["EMAILS_USE_SES"]: import boto.ses try: ses_region = app.config.get("SES_REGION", "us-east-1") ses = boto.ses.connect_to_region(ses_region) except Exception, e: import traceback app.logger.debug(Exception) app.logger.debug(e) app.logger.warn(traceback.format_exc()) return for email in email_list: try: ses.send_email(app.config["MAIL_SENDER"], subject, html, email, format="html") app.logger.debug("Emailed {} - {} ".format(email, subject)) except Exception, e: m = "Failed to send failure message to {} from {} with subject: {}\n{} {}".format( email, app.config["MAIL_SENDER"], subject, Exception, e ) app.logger.debug(m)
def run_reports(overwrite='false'): """ Run project reports. """ overwrite = (overwrite == 'true') print 'Starting at %s' % timezone.now() updated_reports = [] for project in Project.objects.all(): updated_reports.extend(project.run_reports(overwrite=overwrite)) project.social.refresh() if updated_reports: print 'Sending notification email' email_body = render_to_string( 'email.txt', { 'reports': updated_reports }, '/tmp/email.txt' ) if app_config.DEPLOYMENT_TARGET: ses = boto.ses.connect_to_region( app_config.SES_REGION ) ses.send_email( app_config.EMAIL_SEND_ADDRESS, 'Carebot cares!', email_body, [app_config.EMAIL_NOTIFY_ADDRESS] )
def email_subscriptions(xss_uid, url): """ Email all users who are subscribed to assessments. """ email_list = [] notify_jobs = Payload.query.filter_by(id=xss_uid).first() user_notify = User.query.all() # Loop through every User and intersect if the capture is associated with # an assessment they are subscribed to recieve notificaitons for. for user in user_notify: user_subscriptions = [] for assessment in user.assessments: user_subscriptions.append(assessment.id) if len( set(notify_jobs.show_assessment_ids()).intersection( user_subscriptions)) > 0: email_list.append(user.email) import cgi subject = "[Sleepy Puppy] - Capture Recieved From: {}".format( cgi.escape(url, quote=True)) html = "<b>Associated Assessments: </b>{}<br/>".format( cgi.escape(notify_jobs.show_assessment_names(), quote=True)) html += "<b>URL: </b>{}<br/>".format(cgi.escape(url, quote=True)) html += "<b>Parameter: </b>{}<br/>".format( cgi.escape(notify_jobs.parameter, quote=True)) html += "<b>Payload: </b>{}<br/>".format( cgi.escape(notify_jobs.payload, quote=True)) html += "<b>Notes: </b>{}<br/>".format( cgi.escape(notify_jobs.notes, quote=True)) html += "https://{}/admin/capture/{}".format( app.config.get('HOSTNAME', 'localhost'), notify_jobs.id) # If there are people to email, email them that a capture was recieved if email_list: if app.config["EMAILS_USE_SES"]: import boto.ses try: ses_region = app.config.get('SES_REGION', 'us-east-1') ses = boto.ses.connect_to_region(ses_region) except Exception, e: import traceback app.logger.debug(Exception) app.logger.debug(e) app.logger.warn(traceback.format_exc()) return for email in email_list: try: ses.send_email(app.config['MAIL_SENDER'], subject, html, email, format="html") app.logger.debug("Emailed {} - {} ".format(email, subject)) except Exception, e: m = "Failed to send failure message to {} from {} with subject: {}\n{} {}".format( email, app.config['MAIL_SENDER'], subject, Exception, e) app.logger.debug(m)
def email_subscription(payload, the_assessment, url, client_info, model): """ Email notifications for captures, generic collections, and access log """ email_list = [] notify_jobs = Payload.query.filter_by(id=payload).first() user_notify = User.query.all() for user in user_notify: user_subscriptions = [] for assessment in user.assessments: user_subscriptions.append(assessment.id) if the_assessment.id in user_subscriptions: email_list.append(user.email) import cgi if model == "capture": subject = "[Sleepy Puppy] - Capture Recieved From: {}".format( cgi.escape(url, quote=True) ) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True) ) html += "<b>URL: </b>{}<br/>".format( cgi.escape(url, quote=True) ) html += "<b>Payload: </b>{}<br/>".format( cgi.escape(notify_jobs.payload, quote=True) ) if notify_jobs.notes is not None: html += "<b>Notes: </b>{}<br/>".format( cgi.escape(notify_jobs.notes, quote=True) ) html += "<b>Capture: </b>{}://{}/capture/?flt1_0={}&flt3_14={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) elif model == "access_log": subject = "[Sleepy Puppy] - Access Log Request Recieved For Assessment(s): {}".format( cgi.escape(the_assessment.name, quote=True) ) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True) ) html += "<b>Referer: </b>{}<br/>".format( cgi.escape(client_info.referrer or "", quote=True) ) html += "<b>User Agent: </b>{}<br/>".format( cgi.escape(client_info.user_agent or "", quote=True) ) html += "<b>IP Address: </b>{}<br/>".format( cgi.escape(client_info.ip_address, quote=True) ) html += "<b>AccessLog: </b>{}://{}/accesslog/?flt1_7={}&flt2_14={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) elif model == "generic_collector": subject = "[Sleepy Puppy] - Generic Collector Recieved From: {}".format( cgi.escape(client_info.url, quote=True) ) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True) ) html += "<b>Puppyscript Name: </b>{}<br/>".format( cgi.escape(client_info.puppyscript_name or "", quote=True) ) html += "<b>Url: </b>{}<br/>".format( cgi.escape(client_info.url or "", quote=True) ) html += "<b>Referer: </b>{}<br/>".format( cgi.escape(client_info.referrer or "", quote=True) ) html += "<b>Generic Collector: </b>{}://{}/genericcollector/?flt1_0={}&flt2_7={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) # If there are people to email, email them that a capture was recieved if email_list: if app.config["EMAILS_USE_SES"]: import boto.ses try: ses_region = app.config.get('SES_REGION', 'us-east-1') ses = boto.ses.connect_to_region(ses_region) except Exception, e: import traceback app.logger.debug(Exception) app.logger.debug(e) app.logger.warn(traceback.format_exc()) return for email in email_list: try: ses.send_email( app.config['MAIL_SENDER'], subject, html, email, format="html" ) app.logger.debug("Emailed {} - {} ".format(email, subject)) except Exception, e: m = "Failed to send failure message to {} from {} with subject: {}\n{} {}".format( email, app.config['MAIL_SENDER'], subject, Exception, e ) app.logger.debug(m)
def email_subscription(payload, the_assessment, url, client_info, model): """ Email notifications for captures, generic collections, and access log """ email_list = [] notify_jobs = Payload.query.filter_by(id=payload).first() user_notify = User.query.all() for user in user_notify: user_subscriptions = [] for assessment in user.assessments: user_subscriptions.append(assessment.id) if the_assessment.id in user_subscriptions: email_list.append(user.email) import cgi if model == "capture": subject = "[Sleepy Puppy] - Capture Received From: {}".format( cgi.escape(url, quote=True)) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True)) html += "<b>URL: </b>{}<br/>".format(cgi.escape(url, quote=True)) html += "<b>Payload: </b>{}<br/>".format( cgi.escape(notify_jobs.payload, quote=True)) if notify_jobs.notes is not None: html += "<b>Notes: </b>{}<br/>".format( cgi.escape(notify_jobs.notes, quote=True)) html += "<b>Capture: </b>{}://{}/capture/?flt1_0={}&flt3_14={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) elif model == "access_log": subject = "[Sleepy Puppy] - Access Log Request Received For Assessment(s): {}".format( cgi.escape(the_assessment.name, quote=True)) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True)) html += "<b>Referer: </b>{}<br/>".format( cgi.escape(client_info.referrer or "", quote=True)) html += "<b>User Agent: </b>{}<br/>".format( cgi.escape(client_info.user_agent or "", quote=True)) html += "<b>IP Address: </b>{}<br/>".format( cgi.escape(client_info.ip_address, quote=True)) html += "<b>AccessLog: </b>{}://{}/accesslog/?flt1_7={}&flt2_14={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) elif model == "generic_collector": subject = "[Sleepy Puppy] - Generic Collector Received From: {}".format( cgi.escape(client_info.url, quote=True)) html = "<b>Associated Assessment: </b>{}<br/>".format( cgi.escape(the_assessment.name, quote=True)) html += "<b>Puppyscript Name: </b>{}<br/>".format( cgi.escape(client_info.puppyscript_name or "", quote=True)) html += "<b>Url: </b>{}<br/>".format( cgi.escape(client_info.url or "", quote=True)) html += "<b>Referer: </b>{}<br/>".format( cgi.escape(client_info.referrer or "", quote=True)) html += "<b>Generic Collector: </b>{}://{}/genericcollector/?flt1_0={}&flt2_7={}".format( app.config.get('CALLBACK_PROTOCOL', 'https'), app.config.get('HOSTNAME', 'localhost'), payload, the_assessment.name) # If there are people to email, email them that a capture was received if email_list: if app.config["EMAILS_USE_SES"]: import boto.ses try: ses_region = app.config.get('SES_REGION', 'us-east-1') ses = boto.ses.connect_to_region(ses_region) except Exception, e: import traceback app.logger.debug(Exception) app.logger.debug(e) app.logger.warn(traceback.format_exc()) return for email in email_list: try: ses.send_email(app.config['MAIL_SENDER'], subject, html, email, format="html") app.logger.debug("Emailed {} - {} ".format(email, subject)) except Exception, e: m = "Failed to send failure message to {} from {} with subject: {}\n{} {}".format( email, app.config['MAIL_SENDER'], subject, Exception, e) app.logger.debug(m)
def send_match_notification_email(to, subject, body): return ses.send_email(FROM_ADDRESS, subject, body, [to])