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.
|
# The default is to use the SMTP backend.
|
||||||
# Third-party backends can be specified by providing a Python path
|
# Third-party backends can be specified by providing a Python path
|
||||||
# to a module that defines an EmailBackend class.
|
# 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.
|
# Host for sending e-mail.
|
||||||
EMAIL_HOST = 'localhost'
|
EMAIL_HOST = 'localhost'
|
||||||
|
|
|
@ -28,16 +28,17 @@ def get_connection(backend=None, fail_silently=False, **kwds):
|
||||||
"""
|
"""
|
||||||
path = backend or settings.EMAIL_BACKEND
|
path = backend or settings.EMAIL_BACKEND
|
||||||
try:
|
try:
|
||||||
mod = import_module(path)
|
mod_name, klass_name = path.rsplit('.', 1)
|
||||||
|
mod = import_module(mod_name)
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
raise ImproperlyConfigured(('Error importing email backend %s: "%s"'
|
raise ImproperlyConfigured(('Error importing email backend module %s: "%s"'
|
||||||
% (path, e)))
|
% (mod_name, e)))
|
||||||
try:
|
try:
|
||||||
cls = getattr(mod, 'EmailBackend')
|
klass = getattr(mod, klass_name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise ImproperlyConfigured(('Module "%s" does not define a '
|
raise ImproperlyConfigured(('Module "%s" does not define a '
|
||||||
'"EmailBackend" class' % path))
|
'"%s" class' % (mod_name, klass_name)))
|
||||||
return cls(fail_silently=fail_silently, **kwds)
|
return klass(fail_silently=fail_silently, **kwds)
|
||||||
|
|
||||||
|
|
||||||
def send_mail(subject, message, from_email, recipient_list,
|
def send_mail(subject, message, from_email, recipient_list,
|
||||||
|
|
|
@ -43,7 +43,7 @@ def setup_test_environment():
|
||||||
mail.SMTPConnection = locmem.EmailBackend
|
mail.SMTPConnection = locmem.EmailBackend
|
||||||
|
|
||||||
mail.original_email_backend = settings.EMAIL_BACKEND
|
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 = []
|
mail.outbox = []
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ connection with which to send e-mail, you can explicitly request an
|
||||||
SMTP connection::
|
SMTP connection::
|
||||||
|
|
||||||
from django.core.mail import get_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()
|
messages = get_notification_email()
|
||||||
connection.send_messages(messages)
|
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
|
additional arguments, those arguments can be passed to the
|
||||||
:meth:`~django.core.mail.get_connection()` call::
|
: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
|
User Messages API
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
@ -408,7 +408,7 @@ settings file.
|
||||||
The SMTP backend is the default configuration inherited by Django. If you
|
The SMTP backend is the default configuration inherited by Django. If you
|
||||||
want to specify it explicitly, put the following in your settings::
|
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
|
.. 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::
|
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
|
This backend is not intended for use in production -- it is provided as a
|
||||||
convenience that can be used during development.
|
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::
|
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
|
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
|
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::
|
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
|
This backend is not intended for use in production -- it is provided as a
|
||||||
convenience that can be used during development and testing.
|
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
|
As the name suggests the dummy backend does nothing with your messages. To
|
||||||
specify this backend, put the following in your settings::
|
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
|
This backend is not intended for use in production -- it is provided as a
|
||||||
convenience that can be used during development.
|
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
|
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
|
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
|
Custom e-mail backends should subclass ``BaseEmailBackend`` that is located in
|
||||||
the ``django.core.mail.backends.base`` module. A custom e-mail backend must
|
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
|
list of :class:`~django.core.mail.EmailMessage` instances and returns the
|
||||||
number of successfully delivered messages. If your backend has any concept of
|
number of successfully delivered messages. If your backend has any concept of
|
||||||
a persistent session or connection, you should also implement the ``open()``
|
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.
|
implementation.
|
||||||
|
|
||||||
.. _topics-sending-multiple-emails:
|
.. _topics-sending-multiple-emails:
|
||||||
|
|
|
@ -174,7 +174,7 @@ Content
|
||||||
|
|
||||||
# Test that the console backend can be pointed at an arbitrary stream
|
# Test that the console backend can be pointed at an arbitrary stream
|
||||||
>>> s = StringIO()
|
>>> 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)
|
>>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
||||||
1
|
1
|
||||||
>>> print s.getvalue()
|
>>> print s.getvalue()
|
||||||
|
@ -270,7 +270,7 @@ Content
|
||||||
True
|
True
|
||||||
|
|
||||||
# Test custom backend defined in this suite.
|
# 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')
|
>>> hasattr(conn, 'test_outbox')
|
||||||
True
|
True
|
||||||
>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
|
>>> email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
|
||||||
|
@ -280,23 +280,23 @@ True
|
||||||
1
|
1
|
||||||
|
|
||||||
# Test backend argument of mail.get_connection()
|
# 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
|
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
|
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
|
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
|
True
|
||||||
>>> tmp_dir = tempfile.mkdtemp()
|
>>> 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
|
True
|
||||||
>>> shutil.rmtree(tmp_dir)
|
>>> shutil.rmtree(tmp_dir)
|
||||||
>>> isinstance(mail.get_connection(), locmem.EmailBackend)
|
>>> isinstance(mail.get_connection(), locmem.EmailBackend)
|
||||||
True
|
True
|
||||||
|
|
||||||
# Test connection argument of send_mail() et al
|
# 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)
|
>>> send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
||||||
Content-Type: text/plain; charset="utf-8"
|
Content-Type: text/plain; charset="utf-8"
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
|
|
Loading…
Reference in New Issue