コード例 #1
0
ファイル: test_models.py プロジェクト: StetHD/canvas-2
    def test_repeating_exception_bubbles_out(self):
        def send_fail(messages):
            raise Exception

        with self.assertRaises(Exception):
            with mocks.override_send_messages(send_fail):
                send_email('*****@*****.**', '*****@*****.**', 'subjek', 'test', {})
コード例 #2
0
    def test_repeating_exception_bubbles_out(self):
        def send_fail(messages):
            raise Exception

        with self.assertRaises(Exception):
            with mocks.override_send_messages(send_fail):
                send_email('*****@*****.**', '*****@*****.**', 'subjek', 'test', {})
コード例 #3
0
ファイル: test_models.py プロジェクト: StetHD/canvas-2
    def test_ses_blacklist_silently_fails(self):
        def send_fail(messages):
            raise BotoServerError(400, "Bad Request",
            """<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
                 <Error>
                   <Type>Sender</Type>
                   <Code>MessageRejected</Code>
                   <Message>Address blacklisted.</Message>
                 </Error>
                 <RequestId>a693e02d-00f2-11e1-9a52-ed3836840b28</RequestId>
               </ErrorResponse>""")

        with mocks.override_send_messages(send_fail):
            send_email('*****@*****.**', '*****@*****.**', 'subjek', 'test', {})
コード例 #4
0
def _share_by_email(sender, recipients, subject, template_name, context):
    _context = {"sender": sender}
    _context.update(context)

    headers = {"Reply-To": sender.email}

    for recipient in recipients:
        if not User.validate_email(recipient["email"]):
            continue

        try:
            send_email(recipient["email"], settings.UPDATES_EMAIL, subject, template_name, _context, headers=headers)
        except Exception, e:
            client.captureException()
コード例 #5
0
    def test_ses_blacklist_silently_fails(self):
        def send_fail(messages):
            raise BotoServerError(
                400, "Bad Request",
                """<ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
                 <Error>
                   <Type>Sender</Type>
                   <Code>MessageRejected</Code>
                   <Message>Address blacklisted.</Message>
                 </Error>
                 <RequestId>a693e02d-00f2-11e1-9a52-ed3836840b28</RequestId>
               </ErrorResponse>""")

        with mocks.override_send_messages(send_fail):
            send_email('*****@*****.**', '*****@*****.**', 'subjek', 'test',
                       {})
コード例 #6
0
def _share_by_email(sender, recipients, subject, template_name, context):
    _context = {'sender': sender}
    _context.update(context)

    headers = {'Reply-To': sender.email}

    for recipient in recipients:
        if not User.validate_email(recipient['email']):
            continue

        try:
            send_email(recipient['email'],
                       settings.UPDATES_EMAIL,
                       subject,
                       template_name,
                       _context,
                       headers=headers)
        except Exception, e:
            client.captureException()
コード例 #7
0
 def handle(self, from_address, subject, template, id_start, id_end, *args, **options):
     id_start, id_end = int(id_start), int(id_end)
     last = time.time()
     n = 0
     rate = 20 # per second
     err_count = 0
     for user in User.objects.filter(id__gte=id_start).exclude(id__gt=id_end).exclude(email='').order_by('id'):
         n += 1
         if n == rate:
             n = 0
             while time.time() - last <= 1:
                 time.sleep(0.1)
             last = time.time()
         
         print "id: %s username: %s email: %s" % (user.id, user.username, user.email)
         try:
             send_email(user.email, from_address, subject, template, locals())
         except Exception, e:
             import traceback; traceback.print_exc()
             err_count += 1
             if err_count >= 20:
                 raise