Modified the way EMAIL_BACKEND is specified to make it consistent with the new "use the class name" policy for backends.
This is a BACKWARDS-INCOMPATIBLE CHANGE for anyone using a manually specified EMAIL_BACKEND setting. If you have manually specified EMAIL_BACKEND, you will need to append ".EmailBackend" to your existing EMAIL_BACKEND setting. See the django-dev mailing list for details. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
89ded975fe
commit
e07560a88e
|
@ -143,7 +143,7 @@ DATABASES = {
|
|||
# The default is to use the SMTP backend.
|
||||
# Third-party backends can be specified by providing a Python path
|
||||
# to a module that defines an EmailBackend class.
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
|
||||
# Host for sending e-mail.
|
||||
EMAIL_HOST = 'localhost'
|
||||
|
|
|
@ -28,16 +28,17 @@ def get_connection(backend=None, fail_silently=False, **kwds):
|
|||
"""
|
||||
path = backend or settings.EMAIL_BACKEND
|
||||
try:
|
||||
mod = import_module(path)
|
||||
mod_name, klass_name = path.rsplit('.', 1)
|
||||
mod = import_module(mod_name)
|
||||
except ImportError, e:
|
||||
raise ImproperlyConfigured(('Error importing email backend %s: "%s"'
|
||||
% (path, e)))
|
||||
raise ImproperlyConfigured(('Error importing email backend module %s: "%s"'
|
||||
% (mod_name, e)))
|
||||
try:
|
||||
cls = getattr(mod, 'EmailBackend')
|
||||
klass = getattr(mod, klass_name)
|
||||
except AttributeError:
|
||||
raise ImproperlyConfigured(('Module "%s" does not define a '
|
||||
'"EmailBackend" class' % path))
|
||||
return cls(fail_silently=fail_silently, **kwds)
|
||||
'"%s" class' % (mod_name, klass_name)))
|
||||
return klass(fail_silently=fail_silently, **kwds)
|
||||
|
||||
|
||||
def send_mail(subject, message, from_email, recipient_list,
|
||||
|
|
|
@ -43,7 +43,7 @@ def setup_test_environment():
|
|||
mail.SMTPConnection = locmem.EmailBackend
|
||||
|
||||
mail.original_email_backend = settings.EMAIL_BACKEND
|
||||
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem'
|
||||
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
|
||||
mail.outbox = []
|
||||
|
||||
|
|
|
@ -286,7 +286,7 @@ connection with which to send e-mail, you can explicitly request an
|
|||
SMTP connection::
|
||||
|
||||
from django.core.mail import get_connection
|
||||
connection = get_connection('django.core.mail.backends.smtp')
|
||||
connection = get_connection('django.core.mail.backends.smtp.EmailBackend')
|
||||
messages = get_notification_email()
|
||||
connection.send_messages(messages)
|
||||
|
||||
|
@ -294,7 +294,7 @@ If your call to construct an instance of ``SMTPConnection`` required
|
|||
additional arguments, those arguments can be passed to the
|
||||
:meth:`~django.core.mail.get_connection()` call::
|
||||
|
||||
connection = get_connection('django.core.mail.backends.smtp', hostname='localhost', port=1234)
|
||||
connection = get_connection('django.core.mail.backends.smtp.EmailBackend', hostname='localhost', port=1234)
|
||||
|
||||
User Messages API
|
||||
-----------------
|
||||
|
|
|
@ -408,7 +408,7 @@ settings file.
|
|||
The SMTP backend is the default configuration inherited by Django. If you
|
||||
want to specify it explicitly, put the following in your settings::
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
|
||||
.. admonition:: SMTPConnection objects
|
||||
|
||||
|
@ -433,7 +433,7 @@ providing the ``stream`` keyword argument when constructing the connection.
|
|||
|
||||
To specify this backend, put the following in your settings::
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
|
||||
This backend is not intended for use in production -- it is provided as a
|
||||
convenience that can be used during development.
|
||||
|
@ -451,7 +451,7 @@ the ``file_path`` keyword when creating a connection with
|
|||
|
||||
To specify this backend, put the following in your settings::
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.filebased'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
|
||||
EMAIL_FILE_PATH = '/tmp/app-messages' # change this to a proper location
|
||||
|
||||
This backend is not intended for use in production -- it is provided as a
|
||||
|
@ -470,7 +470,7 @@ be send.
|
|||
|
||||
To specify this backend, put the following in your settings::
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
|
||||
This backend is not intended for use in production -- it is provided as a
|
||||
convenience that can be used during development and testing.
|
||||
|
@ -483,7 +483,7 @@ Dummy backend
|
|||
As the name suggests the dummy backend does nothing with your messages. To
|
||||
specify this backend, put the following in your settings::
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.dummy'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
|
||||
|
||||
This backend is not intended for use in production -- it is provided as a
|
||||
convenience that can be used during development.
|
||||
|
@ -495,7 +495,7 @@ Defining a custom e-mail backend
|
|||
|
||||
If you need to change how e-mails are send you can write your own e-mail
|
||||
backend. The ``EMAIL_BACKEND`` setting in your settings file is then the
|
||||
Python import path for your backend.
|
||||
Python import path for your backend class.
|
||||
|
||||
Custom e-mail backends should subclass ``BaseEmailBackend`` that is located in
|
||||
the ``django.core.mail.backends.base`` module. A custom e-mail backend must
|
||||
|
@ -503,7 +503,7 @@ implement the ``send_messages(email_messages)`` method. This method receives a
|
|||
list of :class:`~django.core.mail.EmailMessage` instances and returns the
|
||||
number of successfully delivered messages. If your backend has any concept of
|
||||
a persistent session or connection, you should also implement the ``open()``
|
||||
and ``close()`` methods. Refer to ``SMTPEmailBackend`` for a reference
|
||||
and ``close()`` methods. Refer to ``smtp.EmailBackend`` for a reference
|
||||
implementation.
|
||||
|
||||
.. _topics-sending-multiple-emails:
|
||||
|
|
|
@ -174,7 +174,7 @@ Content
|
|||
|
||||
# Test that the console backend can be pointed at an arbitrary stream
|
||||
>>> s = StringIO()
|
||||
>>> connection = mail.get_connection('django.core.mail.backends.console', stream=s)
|
||||
>>> connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
|
||||
>>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
||||
1
|
||||
>>> print s.getvalue()
|
||||
|
@ -270,7 +270,7 @@ Content
|
|||
True
|
||||
|
||||
# Test custom backend defined in this suite.
|
||||
>>> conn = mail.get_connection('regressiontests.mail.custombackend')
|
||||
>>> conn = mail.get_connection('regressiontests.mail.custombackend.EmailBackend')
|
||||
>>> hasattr(conn, 'test_outbox')
|
||||
True
|
||||
>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
|
||||
|
@ -280,23 +280,23 @@ True
|
|||
1
|
||||
|
||||
# Test backend argument of mail.get_connection()
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.smtp'), smtp.EmailBackend)
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend)
|
||||
True
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.locmem'), locmem.EmailBackend)
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend)
|
||||
True
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.dummy'), dummy.EmailBackend)
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.dummy.EmailBackend'), dummy.EmailBackend)
|
||||
True
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.console'), console.EmailBackend)
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.console.EmailBackend'), console.EmailBackend)
|
||||
True
|
||||
>>> tmp_dir = tempfile.mkdtemp()
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.filebased', file_path=tmp_dir), filebased.EmailBackend)
|
||||
>>> isinstance(mail.get_connection('django.core.mail.backends.filebased.EmailBackend', file_path=tmp_dir), filebased.EmailBackend)
|
||||
True
|
||||
>>> shutil.rmtree(tmp_dir)
|
||||
>>> isinstance(mail.get_connection(), locmem.EmailBackend)
|
||||
True
|
||||
|
||||
# Test connection argument of send_mail() et al
|
||||
>>> connection = mail.get_connection('django.core.mail.backends.console')
|
||||
>>> connection = mail.get_connection('django.core.mail.backends.console.EmailBackend')
|
||||
>>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
MIME-Version: 1.0
|
||||
|
|
Loading…
Reference in New Issue