Пример #1
0
    def test_mass_mail_pre_send(self):
        test_list = []

        def pre_send_signal(sender, message, **kwargs):
            self.assertEqual(message.subject, u'件名')
            self.assertEqual(message.body, u'本文')
            test_list.extend(message.to)
        mail_pre_send.connect(pre_send_signal)

        send_mass_mail(((
            u'件名',
            u'本文',
            u'差出人 <*****@*****.**>',
            [u'宛先 <*****@*****.**>' % i],
        ) for i in range(10)), encoding='iso-2022-jp')

        self.assertEqual(test_list, [
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
        ])
Пример #2
0
    def test_mass_mail_pre_send(self):
        test_list = []

        def pre_send_signal(sender, message, **kwargs):
            self.assertEqual(message.subject, u'件名')
            self.assertEqual(message.body, u'本文')
            test_list.extend(message.to)

        mail_pre_send.connect(pre_send_signal)

        send_mass_mail(((
            u'件名',
            u'本文',
            u'差出人 <*****@*****.**>',
            [u'宛先 <*****@*****.**>' % i],
        ) for i in range(10)),
                       encoding='iso-2022-jp')

        self.assertEqual(test_list, [
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
            u'宛先 <*****@*****.**>',
        ])
Пример #3
0
    def test_pre_send_signal(self):
        def pre_send_signal(sender, message, **kwargs):
            message.from_email = message.from_email.replace(u'\uff5e', u'\u301c')
            message.to = map(lambda x: x.replace(u'\uff5e', u'\u301c'), message.to)
            message.bcc = map(lambda x: x.replace(u'\uff5e', u'\u301c'), message.bcc)
            message.subject = message.subject.replace(u'\uff5e', u'\u301c')
            message.body = message.body.replace(u'\uff5e', u'\u301c')
        mail_pre_send.connect(pre_send_signal)

        send_mail(
            u'件名',
            u'本文~テスト',
            u'差出人 <*****@*****.**>',
            [u'宛先 <*****@*****.**>'],
        )

        message = django_mail.outbox[0].message()

        self.assertEqual(str(message['Subject']), "=?ISO-2022-JP?b?GyRCN29MPhsoQg==?=")
        self.assertEqual(str(message['To']),
                         "=?ISO-2022-JP?b?GyRCMDhAaBsoQg==?= <*****@*****.**>")
        self.assertEqual(str(message['From']),
                         "=?ISO-2022-JP?b?GyRCOjk9UD9NGyhC?= <*****@*****.**>")
        self.assertEqual(message['Content-Transfer-Encoding'], '7bit')
        self.assertEqual(message['Content-Type'], 'text/plain; charset="ISO-2022-JP"')
        self.assertEqual(message.get_payload(), "\x1b$BK\\J8!A%F%9%H\x1b(B")
Пример #4
0
    def test_pre_send_signal(self):
        def pre_send_signal(sender, message, **kwargs):
            message.from_email = message.from_email.replace(
                u'\uff5e', u'\u301c')
            message.to = [x.replace(u'\uff5e', u'\u301c') for x in message.to]
            message.bcc = [
                x.replace(u'\uff5e', u'\u301c') for x in message.bcc
            ]
            message.subject = message.subject.replace(u'\uff5e', u'\u301c')
            message.body = message.body.replace(u'\uff5e', u'\u301c')

        mail_pre_send.connect(pre_send_signal)

        send_mail(
            u'件名',
            u'本文~テスト',
            u'差出人 <*****@*****.**>',
            [u'宛先 <*****@*****.**>'],
        )

        message = django_mail.outbox[0].message()

        self.assertEqual(str(message['Subject']),
                         "=?iso-2022-jp?b?GyRCN29MPhsoQg==?=")
        self.assertEqual(
            str(message['To']),
            "=?iso-2022-jp?b?GyRCMDhAaBsoQg==?= <*****@*****.**>")
        self.assertEqual(
            str(message['From']),
            "=?iso-2022-jp?b?GyRCOjk9UD9NGyhC?= <*****@*****.**>")
        self.assertEqual(message['Content-Transfer-Encoding'], '7bit')
        self.assertEqual(message['Content-Type'],
                         'text/plain; charset="iso-2022-jp"')
        self.assertEqual(message.get_payload(), "\x1b$BK\\J8!A%F%9%H\x1b(B")