Opened 15 years ago
Last modified 15 years ago
#13641 closed
The location of the get_connection() function does not correspond with the documentation — at Initial Version
Reported by: | caumons | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.1 |
Severity: | Keywords: | email, connection, get_connection, SMTPConnection | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If we try to import the get_connection() function from django.core.mail as specified in the documentation we get the following ImportError in Django 1.1.1:
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
from django.core.mail import get_connection
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name get_connection
Looking at the source code of the module situated at /usr/local/lib/python2.6/dist-packages/django/core/mail.py we can check that no get_connection() is declared in the module.
If we want to create a connection to send emails, we have to instantiate the SMTPConnection class and then call its methods. For example:
mailConnection = SMTPConnection()
mailConnection.open()
mailConnection.send_messages([email1, email2])
mailConnection.close()
get_connection(self, fail_silently=False) is a method inside the EmailMessage class situated in line 228 and used in line 266, not a function.
The solution I see is to update the documentation referring to emails section.