Example #1
0
    def send_mail(self, recipients='', subject='', message=''):

        msg = MailAction()

        msg.source = self.SENDER

        # If we're in debug mode, the email goes to the configured debug email.
        # Or, if we don't have recipients
        if self.debug or not recipients:
            msg.recipients = self.debug_email
        else:
            msg.recipients = recipients

        msg.subject = "%s: %s" % (self.SUBJECT_PREFIX, subject)
        msg.message = message

        # If we're in debug mode, log the message
        if self.debug:
            self.log(summary="DEBUG: Send email %s to %s" % (msg.subject, recipients))

        # Send the email and log error
        try:
            m = MailActionExecutor(self.context, msg, self.event)
            m()
        except:
            self.log(summary="Error sending email %s to %s" % (msg.subject, msg.recipients),
                     severity=ERROR)