示例#1
0
    def test_message_with_smart_spoofing_setting_and_not_allowed(self):
        """Testing EmailMessage.message with
        settings.EMAIL_ENABLE_SMART_SPOOFING=True and
        From address not allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=quarantine;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(
            email.extra_headers['From'],
            'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(
            msg['From'], 'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'], 'Doc Dwarf <*****@*****.**>')
示例#2
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_enable_smart_spoofing_false(self):
        """Testing EmailMessage.message with enable_smart_spoofing=False"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=False)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], 'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#3
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_from_spoofing_setting_smart_and_not_allowed(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=smart and From address not allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=quarantine;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#4
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_from_spoofing_setting_never(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=never
        """
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#5
0
    def test_message_with_enable_smart_spoofing_false(self):
        """Testing EmailMessage.message with enable_smart_spoofing=False"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=False)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], 'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#6
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_sender(self):
        """Testing EmailMessage.message with sender="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**',
                             enable_smart_spoofing=False)

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
示例#7
0
    def test_message_with_from_spoofing_setting_never(self):
        """Testing EmailMessage.message with
        settings.DJBLETS_EMAIL_FROM_SPOOFING=never
        """
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf via My Service <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#8
0
    def test_message_with_sender(self):
        """Testing EmailMessage.message with sender="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**',
                             enable_smart_spoofing=False)

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
示例#9
0
    def test_send_with_unicode_subject(self):
        """Testing EmailMessage.send with a Unicode subject"""
        email = EmailMessage(subject='\U0001f604',
                             text_body='This is a test',
                             html_body='<p>This is a test</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
示例#10
0
文件: tests.py 项目: adhulipa/djblets
    def test_send_email_unicode_subject(self):
        """Testing sending an EmailMessage with a unicode subject"""
        email = EmailMessage(subject='\ud83d\ude04',
                             text_body='This is a test',
                             html_body='<p>This is a test</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
示例#11
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_prevent_auto_responses_false(self):
        """Testing EmailMessage.message with prevent_auto_responses=False"""
        # prevent_auto_responses is False by default, so test with that case
        # to ensure it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('X-Auto-Response-Suppress', email._headers)

        msg = email.message()
        self.assertNotIn('X-Auto-Response-Suppress', msg)
示例#12
0
    def test_message_with_prevent_auto_responses_false(self):
        """Testing EmailMessage.message with prevent_auto_responses=False"""
        # prevent_auto_responses is False by default, so test with that case
        # to ensure it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('X-Auto-Response-Suppress', email._headers)

        msg = email.message()
        self.assertNotIn('X-Auto-Response-Suppress', msg)
示例#13
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_auto_generated_false(self):
        """Testing EmailMessage.message with auto_generated=False"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('Auto-Submitted', email._headers)

        msg = email.message()
        self.assertNotIn('Auto-Submitted', msg)
示例#14
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_auto_generated_true(self):
        """Testing EmailMessage.message with auto_generated=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             auto_generated=True)

        self.assertIn('Auto-Submitted', email._headers)
        self.assertEqual(email._headers['Auto-Submitted'], 'auto-generated')

        msg = email.message()
        self.assertEqual(msg['Auto-Submitted'], 'auto-generated')
示例#15
0
文件: tests.py 项目: adhulipa/djblets
    def test_send_email_unicode_body(self):
        """Testing sending an EmailMessage with a unicode body"""
        email = EmailMessage(subject='Test email',
                             text_body='\ud83d\ude04',
                             html_body='<p>\ud83d\ude04</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        # If the e-mail doesn't send correctly, it will raise a
        # UnicodeDecodeError.
        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
示例#16
0
    def test_message_with_auto_generated_false(self):
        """Testing EmailMessage.message with auto_generated=False"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('Auto-Submitted', email._headers)

        msg = email.message()
        self.assertNotIn('Auto-Submitted', msg)
示例#17
0
    def test_message_with_auto_generated_true(self):
        """Testing EmailMessage.message with auto_generated=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             auto_generated=True)

        self.assertIn('Auto-Submitted', email._headers)
        self.assertEqual(email._headers['Auto-Submitted'], 'auto-generated')

        msg = email.message()
        self.assertEqual(msg['Auto-Submitted'], 'auto-generated')
示例#18
0
    def test_send_with_unicode_body(self):
        """Testing EmailMessage.send with a Unicode body"""
        email = EmailMessage(subject='Test email',
                             text_body='\U0001f604',
                             html_body='<p>\U0001f604</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        # If the e-mail doesn't send correctly, it will raise a
        # UnicodeDecodeError.
        with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
            email.send()
    def _create_message(self):
        """Return a new EmailMessage for testing.

        This will contain a sample recipient and initial
        :mailheader:`Message-ID`.

        Returns:
            djblets.mail.message.EmailMessage:
            The resulting message.
        """
        message = EmailMessage(to=['*****@*****.**'])
        message.extra_headers['Message-ID'] = '<*****@*****.**>'

        return message
示例#20
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_prevent_auto_responses_true(self):
        """Testing EmailMessage.message with prevent_auto_responses=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             prevent_auto_responses=True)

        self.assertIn('X-Auto-Response-Suppress', email._headers)
        self.assertEqual(email._headers['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')

        msg = email.message()
        self.assertEqual(msg['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')
示例#21
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_extra_headers_dict(self):
        """Testing EmailMessage.message with extra headers as a dict"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(message['X-Foo'], 'Bar')
示例#22
0
    def test_message_with_prevent_auto_responses_true(self):
        """Testing EmailMessage.message with prevent_auto_responses=True"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             prevent_auto_responses=True)

        self.assertIn('X-Auto-Response-Suppress', email._headers)
        self.assertEqual(email._headers['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')

        msg = email.message()
        self.assertEqual(msg['X-Auto-Response-Suppress'],
                         'DR, RN, OOF, AutoReply')
示例#23
0
    def test_message_with_extra_headers_dict(self):
        """Testing EmailMessage.message with extra headers as a dict"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(message['X-Foo'], 'Bar')
示例#24
0
    def test_message_with_in_reply_to(self):
        """Testing EmailMessage.message with in_reply_to="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             in_reply_to='*****@*****.**')

        self.assertIn('In-Reply-To', email._headers)
        self.assertIn('References', email._headers)
        self.assertEqual(email._headers['In-Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['References'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['In-Reply-To'], '*****@*****.**')
        self.assertEqual(msg['References'], '*****@*****.**')
示例#25
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_in_reply_to(self):
        """Testing EmailMessage.message with in_reply_to="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             in_reply_to='*****@*****.**')

        self.assertIn('In-Reply-To', email._headers)
        self.assertIn('References', email._headers)
        self.assertEqual(email._headers['In-Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['References'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['In-Reply-To'], '*****@*****.**')
        self.assertEqual(msg['References'], '*****@*****.**')
示例#26
0
    def test_message_with_extra_headers_multivalue_dict(self):
        """Testing EmailMessage.message with extra headers as a MultiValueDict
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(set(message.get_all('X-Foo')), set(header_values))
示例#27
0
文件: tests.py 项目: adhulipa/djblets
    def test_extra_headers_dict(self):
        """Testing sending extra headers as a dict with an e-mail message"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers={
                                 'X-Foo': 'Bar',
                             })

        email.send()

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]

        self.assertIn('X-Foo', message._headers)
        self.assertEqual(message._headers['X-Foo'], 'Bar')
示例#28
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_extra_headers_multivalue_dict(self):
        """Testing EmailMessage.message with extra headers as a MultiValueDict
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        message = email.message()

        self.assertIn('X-Foo', message)
        self.assertEqual(set(message.get_all('X-Foo')),
                         set(header_values))
示例#29
0
    def test_init_with_text_body_as_bytes(self):
        """Testing EmailMessage.__init__ with text_body=<bytes>"""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body=b'This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertEqual(email.body, 'This is a test.')
        self.assertIsInstance(email.body, six.text_type)
示例#30
0
    def test_init_with_html_body(self):
        """Testing EmailMessage.__init__ with html_body="""
        # auto_generated is True by default, so test with that case to ensure
        # it doesn't unintentionally change.
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertEqual(email.alternatives,
                         [('<p>This is a test.</p>', 'text/html')])
示例#31
0
文件: tests.py 项目: adhulipa/djblets
    def test_extra_headers_multivalue_dict(self):
        """Testing sending extra headers as a MultiValueDict with an e-mail
        message
        """
        header_values = ['Bar', 'Baz']

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             headers=MultiValueDict({
                                 'X-Foo': header_values,
                             }))

        email.send()

        self.assertEqual(len(mail.outbox), 1)
        message = mail.outbox[0]

        self.assertIn('X-Foo', message._headers)
        self.assertEqual(set(message._headers.getlist('X-Foo')),
                         set(header_values))
示例#32
0
文件: tests.py 项目: adhulipa/djblets
    def test_headers_from_sender(self):
        """Testing EmailMessage From/Sender headers"""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             html_body='<p>This is a test.</p>',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'],
                             sender='*****@*****.**')

        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'], '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Sender'], '*****@*****.**')
        self.assertEqual(msg['X-Sender'], '*****@*****.**')
示例#33
0
文件: tests.py 项目: davidt/djblets
    def test_message_with_from(self):
        """Testing EmailMessage.message with from_email="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email._headers['X-Sender'],
                         settings.DEFAULT_FROM_EMAIL)

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Reply-To'], '*****@*****.**')
示例#34
0
    def test_message_with_from(self):
        """Testing EmailMessage.message with from_email="""
        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='*****@*****.**',
                             to=['*****@*****.**'])

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'], '*****@*****.**')
        self.assertEqual(email._headers['Reply-To'], '*****@*****.**')
        self.assertEqual(email._headers['Sender'], settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email._headers['X-Sender'],
                         settings.DEFAULT_FROM_EMAIL)

        msg = email.message()
        self.assertEqual(msg['From'], '*****@*****.**')
        self.assertEqual(msg['Reply-To'], '*****@*****.**')
示例#35
0
    def test_message_with_enable_smart_spoofing_true_and_allowed(self):
        """Testing EmailMessage.message with enable_smart_spoofing=True and
        From address allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=none;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=True)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
示例#36
0
文件: tests.py 项目: chipx86/djblets
    def test_message_with_enable_smart_spoofing_true_and_allowed(self):
        """Testing EmailMessage.message with enable_smart_spoofing=True and
        From address allowed
        """
        self.dmarc_txt_records['_dmarc.corp.example.com'] = \
            'v=DMARC1; p=none;'

        email = EmailMessage(subject='Test email',
                             text_body='This is a test.',
                             from_email='Doc Dwarf <*****@*****.**>',
                             sender='*****@*****.**',
                             to=['*****@*****.**'],
                             enable_smart_spoofing=True)

        self.assertNotIn('From', email._headers)
        self.assertNotIn('Sender', email.extra_headers)
        self.assertNotIn('X-Sender', email.extra_headers)
        self.assertIn('From', email.extra_headers)
        self.assertIn('Sender', email._headers)
        self.assertIn('X-Sender', email._headers)
        self.assertIn('Reply-To', email._headers)
        self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL)
        self.assertEqual(email.extra_headers['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(email._headers['Sender'],
                         '*****@*****.**')
        self.assertEqual(email._headers['X-Sender'],
                         '*****@*****.**')

        msg = email.message()
        self.assertEqual(msg['From'],
                         'Doc Dwarf <*****@*****.**>')
        self.assertEqual(msg['Reply-To'],
                         'Doc Dwarf <*****@*****.**>')