當前位置: 首頁>>代碼示例>>Python>>正文


Python smtp.EmailBackend方法代碼示例

本文整理匯總了Python中django.core.mail.backends.smtp.EmailBackend方法的典型用法代碼示例。如果您正苦於以下問題:Python smtp.EmailBackend方法的具體用法?Python smtp.EmailBackend怎麽用?Python smtp.EmailBackend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.core.mail.backends.smtp的用法示例。


在下文中一共展示了smtp.EmailBackend方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: clean

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def clean(self):
        cleaned_data = super().clean()
        smtp_email_backend = EmailBackend(
            host=cleaned_data.get('smtp_host'),
            port=cleaned_data.get('smtp_port'),
            username=cleaned_data.get('smtp_username'),
            password=cleaned_data.get('smtp_password'),
            use_tls=cleaned_data.get('smtp_use_tls'),
            fail_silently=False,
            use_ssl=cleaned_data.get('smtp_use_ssl'),
            timeout=cleaned_data.get('smtp_timeout'),
            ssl_keyfile=cleaned_data.get('smtp_ssl_keyfile'),
            ssl_certfile=cleaned_data.get('smtp_ssl_certfile')
        )
        try:
            smtp_email_backend.open()
        except ConnectionRefusedError:
            raise ValidationError(_('Connection refused'), code='connection_refused')
        except SMTPAuthenticationError as err:
            raise ValidationError(str(err), code='auth_error')
        return cleaned_data 
開發者ID:vitorfs,項目名稱:colossus,代碼行數:23,代碼來源:forms.py

示例2: test_backend_arg

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_backend_arg(self):
        """Test backend argument of mail.get_connection()"""
        self.assertIsInstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend)
        self.assertIsInstance(
            mail.get_connection('django.core.mail.backends.locmem.EmailBackend'),
            locmem.EmailBackend
        )
        self.assertIsInstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend)
        self.assertIsInstance(
            mail.get_connection('django.core.mail.backends.console.EmailBackend'),
            console.EmailBackend
        )
        with tempfile.TemporaryDirectory() as tmp_dir:
            self.assertIsInstance(
                mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir),
                filebased.EmailBackend
            )
        self.assertIsInstance(mail.get_connection(), locmem.EmailBackend) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:20,代碼來源:tests.py

示例3: test_console_stream_kwarg

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_console_stream_kwarg(self):
        """
        The console backend can be pointed at an arbitrary stream.
        """
        s = StringIO()
        connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
        send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
        message = s.getvalue().split('\n' + ('-' * 79) + '\n')[0].encode()
        self.assertMessageHasHeaders(message, {
            ('MIME-Version', '1.0'),
            ('Content-Type', 'text/plain; charset="utf-8"'),
            ('Content-Transfer-Encoding', '7bit'),
            ('Subject', 'Subject'),
            ('From', 'from@example.com'),
            ('To', 'to@example.com')})
        self.assertIn(b'\nDate: ', message) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例4: email_backend

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def email_backend(self):
        return EmailBackend(**self.email_conf['connection']) 
開發者ID:aropan,項目名稱:clist,代碼行數:4,代碼來源:models.py

示例5: get_smtp_connection

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def get_smtp_connection(self):
        """Get SMTP connection.
        :return: SMTP connection
        """
        if not self.smtp_host:
            return None

        options = {
            'use_ssl': self.smtp_use_ssl
        }

        # add host / port infos
        if ':' in self.smtp_host:
            host, port = self.smtp_host.split(':')
            options['host'] = host
            options['port'] = int(port)

        else:
            options['host'] = self.smtp_host

        # add cred infos
        if self.smtp_username:
            options['username'] = self.smtp_username

        if self.smtp_password:
            options['password'] = self.smtp_password

        return EmailBackend(**options) 
開發者ID:atexio,項目名稱:mercure,代碼行數:30,代碼來源:campaign.py

示例6: test_dummy_backend

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_dummy_backend(self):
        """
        Make sure that dummy backends returns correct number of sent messages
        """
        connection = dummy.EmailBackend()
        email = EmailMessage(
            'Subject', 'Content', 'bounce@example.com', ['to@example.com'],
            headers={'From': 'from@example.com'},
        )
        self.assertEqual(connection.send_messages([email, email, email]), 3) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:tests.py

示例7: test_custom_backend

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_custom_backend(self):
        """Test custom backend defined in this suite."""
        conn = mail.get_connection('mail.custombackend.EmailBackend')
        self.assertTrue(hasattr(conn, 'test_outbox'))
        email = EmailMessage(
            'Subject', 'Content', 'bounce@example.com', ['to@example.com'],
            headers={'From': 'from@example.com'},
        )
        conn.send_messages([email])
        self.assertEqual(len(conn.test_outbox), 1) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:tests.py

示例8: test_connection_arg

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_connection_arg(self):
        """Test connection argument to send_mail(), et. al."""
        mail.outbox = []

        # Send using non-default connection
        connection = mail.get_connection('mail.custombackend.EmailBackend')
        send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject')

        connection = mail.get_connection('mail.custombackend.EmailBackend')
        send_mass_mail([
            ('Subject1', 'Content1', 'from1@example.com', ['to1@example.com']),
            ('Subject2', 'Content2', 'from2@example.com', ['to2@example.com']),
        ], connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 2)
        self.assertEqual(connection.test_outbox[0].subject, 'Subject1')
        self.assertEqual(connection.test_outbox[1].subject, 'Subject2')

        connection = mail.get_connection('mail.custombackend.EmailBackend')
        mail_admins('Admin message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Django] Admin message')

        connection = mail.get_connection('mail.custombackend.EmailBackend')
        mail_managers('Manager message', 'Content', connection=connection)
        self.assertEqual(mail.outbox, [])
        self.assertEqual(len(connection.test_outbox), 1)
        self.assertEqual(connection.test_outbox[0].subject, '[Django] Manager message') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:34,代碼來源:tests.py

示例9: test_locmem_shared_messages

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_locmem_shared_messages(self):
        """
        Make sure that the locmen backend populates the outbox.
        """
        connection = locmem.EmailBackend()
        connection2 = locmem.EmailBackend()
        email = EmailMessage(
            'Subject', 'Content', 'bounce@example.com', ['to@example.com'],
            headers={'From': 'from@example.com'},
        )
        connection.send_messages([email])
        connection2.send_messages([email])
        self.assertEqual(len(mail.outbox), 2) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:15,代碼來源:tests.py

示例10: test_email_authentication_use_settings

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_email_authentication_use_settings(self):
        backend = smtp.EmailBackend()
        self.assertEqual(backend.username, 'not empty username')
        self.assertEqual(backend.password, 'not empty password') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例11: test_email_authentication_override_settings

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_email_authentication_override_settings(self):
        backend = smtp.EmailBackend(username='username', password='password')
        self.assertEqual(backend.username, 'username')
        self.assertEqual(backend.password, 'password') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例12: test_email_disabled_authentication

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_email_disabled_authentication(self):
        backend = smtp.EmailBackend(username='', password='')
        self.assertEqual(backend.username, '')
        self.assertEqual(backend.password, '') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例13: test_auth_attempted

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_auth_attempted(self):
        """
        Opening the backend with non empty username/password tries
        to authenticate against the SMTP server.
        """
        backend = smtp.EmailBackend(
            username='not empty username', password='not empty password')
        with self.assertRaisesMessage(SMTPException, 'SMTP AUTH extension not supported by server.'):
            with backend:
                pass 
開發者ID:nesdis,項目名稱:djongo,代碼行數:12,代碼來源:tests.py

示例14: test_server_open

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_server_open(self):
        """
        open() returns whether it opened a connection.
        """
        backend = smtp.EmailBackend(username='', password='')
        self.assertIsNone(backend.connection)
        opened = backend.open()
        backend.close()
        self.assertIs(opened, True) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:tests.py

示例15: test_server_login

# 需要導入模塊: from django.core.mail.backends import smtp [as 別名]
# 或者: from django.core.mail.backends.smtp import EmailBackend [as 別名]
def test_server_login(self):
        """
        Even if the Python SMTP server doesn't support authentication, the
        login process starts and the appropriate exception is raised.
        """
        class CustomEmailBackend(smtp.EmailBackend):
            connection_class = FakeAUTHSMTPConnection

        backend = CustomEmailBackend(username='username', password='password')
        with self.assertRaises(SMTPAuthenticationError):
            with backend:
                pass 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:tests.py


注:本文中的django.core.mail.backends.smtp.EmailBackend方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。