def send_email(subsystem, sender, recipients, subject, html_body=None, text_body=None, message_uuid=None): """Send an email to a list of recipients using the system configured email method (SES or SMTP) Args: subsystem (str): Name of the subsystem where the email originated from sender (str): From email address recipients (`list` of `str`): List of recipient email addresses subject (str): Subject of the email html_body (str): HTML body of the email text_body (str): Text body of the email message_uuid (str): Optional UUID message identifier. If not provided one will be generated automatically Returns: `None` """ if type(recipients) == str: recipients = [recipients] recipients = list(set(recipients)) send_notification( subsystem=subsystem, recipients=[NotificationContact('email', x) for x in recipients], subject=subject, body_html=html_body, body_text=text_body)
def put(self, emailId): email = db.Email.find_one(Email.email_id == emailId) if not email: return self.make_response( { 'message': 'Email not found', 'email': None }, HTTP.NOT_FOUND) try: send_notification(subsystem=email.subsystem, recipients=[ NotificationContact('email', x) for x in email.recipients ], subject=email.subject, body_html=email.message_html, body_text=email.message_text) auditlog(event='email.resend', actor=session['user'].username, data={'emailId': emailId}) return self.make_response('Email resent successfully') except EmailSendError as ex: self.log.exception('Failed resending email {0}: {1}'.format( email.email_id, ex)) return self.make_response( 'Failed resending the email: {0}'.format(ex), HTTP.UNAVAILABLE)
def send_message(contacts, message): """List of contacts the send the message to. You can send messages either to channels and private groups by using the following formats #channel-name @username-direct-message If the channel is the name of a private group / channel, you must first invite the bot to the channel to ensure it is allowed to send messages to the group. Returns true if the message was sent, else `False` Args: contacts (:obj:`list` of `str`,`str`): List of contacts message (str): Message to send Returns: `bool` """ if type(contacts) == str: contacts = [contacts] recipients = list(set(contacts)) send_notification( subsystem='UNKNOWN', recipients=[NotificationContact('slack', x) for x in recipients], subject=None, body_html=message, body_text=message )
def notify(self, notices): """Send notifications to the recipients provided Args: notices (:obj:`dict` of `str`: `list`): A dictionary mapping notification messages to the recipient. Returns: `None` """ tmpl_html = get_template('required_tags_notice.html') tmpl_text = get_template('required_tags_notice.txt') for recipient, data in list(notices.items()): body_html = tmpl_html.render(data=data) body_text = tmpl_text.render(data=data) send_notification(subsystem=self.ns, recipients=[recipient], subject=self.email_subject, body_html=body_html, body_text=body_text)
def notify(self, notices): """Send notifications to the users via. the provided methods Args: notices (:obj:`dict` of `str`: `dict`): List of the notifications to send Returns: `None` """ issues_html = get_template('unattached_ebs_volume.html') issues_text = get_template('unattached_ebs_volume.txt') for recipient, issues in list(notices.items()): if issues: message_html = issues_html.render(issues=issues) message_text = issues_text.render(issues=issues) send_notification(subsystem=self.name, recipients=[recipient], subject=self.subject, body_html=message_html, body_text=message_text)
def notify(self, new_issues, existing_issues, fixed_issues): """Send notifications (email, slack, etc.) for any issues that are currently open or has just been closed Args: new_issues (`list` of :obj:`DomainHijackIssue`): List of newly discovered issues existing_issues (`list` of :obj:`DomainHijackIssue`): List of existing open issues fixed_issues (`list` of `dict`): List of fixed issues Returns: None """ if len(new_issues + existing_issues + fixed_issues) > 0: maxlen = max(len(x['properties']['source']) for x in (new_issues + existing_issues + fixed_issues)) + 2 text_tmpl = get_template('domain_hijacking.txt') html_tmpl = get_template('domain_hijacking.html') issues_text = text_tmpl.render( new_issues=new_issues, existing_issues=existing_issues, fixed_issues=fixed_issues, maxlen=maxlen ) issues_html = html_tmpl.render( new_issues=new_issues, existing_issues=existing_issues, fixed_issues=fixed_issues, maxlen=maxlen ) try: send_notification( subsystem=self.name, recipients=[NotificationContact('email', addr) for addr in self.recipients], subject=self.subject, body_html=issues_html, body_text=issues_text ) except Exception as ex: self.log.exception('Failed sending notification email: {}'.format(ex))