Exemplo n.º 1
0
 def test_sendmail(self):
     "Test sendmail"
     message = Mock()
     server = Mock()
     sendmail("*****@*****.**", "*****@*****.**", message, server=server)
     server.sendmail.assert_called_with("*****@*****.**", "*****@*****.**", message.as_string())
     server.quit.assert_not_called()
Exemplo n.º 2
0
 def send_message(cls, message):
     to_addr = cls.prepare_message()
     if to_addr:
         from_addr = config.get('email', 'uri')
         subject = cls.raise_user_error('email_subject',
                                        raise_exception=False)
         msg = cls.create_message(from_addr, [to_addr], subject, message)
         sendmail(from_addr, [to_addr], msg)
Exemplo n.º 3
0
 def test_sendmail(self):
     'Test sendmail'
     message = Mock()
     server = Mock()
     sendmail(
         '*****@*****.**', '*****@*****.**', message, server=server)
     server.sendmail.assert_called_with(
         '*****@*****.**', '*****@*****.**', message.as_string())
     server.quit.assert_not_called()
Exemplo n.º 4
0
    def send_error_message(cls, cron):
        tb_s = ''.join(traceback.format_exception(*sys.exc_info()))
        # On Python3, the traceback is already a unicode
        if hasattr(tb_s, 'decode'):
            tb_s = tb_s.decode('utf-8', 'ignore')
        subject = cls.raise_user_error('request_title', raise_exception=False)
        body = cls.raise_user_error('request_body',
                                    (cron.name, cron.__url__, tb_s),
                                    raise_exception=False)

        from_addr = config.get('email', 'from')
        to_addr = cron.request_user.email

        msg = MIMEText(body, _charset='utf-8')
        msg['To'] = to_addr
        msg['From'] = from_addr
        msg['Subject'] = Header(subject, 'utf-8')
        if not to_addr:
            logger.error(msg.as_string())
        else:
            sendmail(from_addr, to_addr, msg)