#34783: No module named 'smtp' when trying to send an email
-------------------------------------+-------------------------------------
               Reporter:  Rami       |          Owner:  nobody
  Boutassghount                      |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  4.2
  (Mail)                             |       Keywords:  mail, smtp,
               Severity:  Normal     |  emailbackend
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I am not sure if it's a bug or not, but I mark it as that since I am just
 following the docs for setting up the Email Backend.

 I get the Exception ''ModuleNotFoundError at /password/reset/ No module
 named 'smtp''' when I just try to send an Email using the function
 send_mail.

 Here is what I am using:
 * Ubuntu 22.04
 * Python 3.11.4
 * Django 4.2.2
 * EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

 An here is the complete traceback.

 {{{
 ModuleNotFoundError                       Traceback (most recent call
 last)
 Cell In[3], line 1
 ----> 1 send_mail("hello", "hi bro, what up?", "[email protected]",
 ["[email protected]"])

 File ~/nicecv/venv/lib/python3.11/site-
 packages/django/core/mail/__init__.py:76, in send_mail(subject, message,
 from_email, recipient_list, fail_silently, auth_user, auth_password,
 connection, html_message)
      54 def send_mail(
      55     subject,
      56     message,
    (...)
      63     html_message=None,
      64 ):
      65     """
      66     Easy wrapper for sending a single message to a recipient list.
 All members
      67     of the recipient list will see the other recipients in the
 'To' field.
    (...)
      74     functionality should use the EmailMessage class directly.
      75     """
 ---> 76     connection = connection or get_connection(
      77         username=auth_user,
      78         password=auth_password,
      79         fail_silently=fail_silently,
      80     )
      81     mail = EmailMultiAlternatives(
      82         subject, message, from_email, recipient_list,
 connection=connection
      83     )
      84     if html_message:

 File ~/nicecv/venv/lib/python3.11/site-
 packages/django/core/mail/__init__.py:50, in get_connection(backend,
 fail_silently, **kwds)
      42 def get_connection(backend=None, fail_silently=False, **kwds):
      43     """Load an email backend and return an instance of it.
      44
      45     If backend is None (default), use settings.EMAIL_BACKEND.
    (...)
      48     constructor of the backend.
      49     """
 ---> 50     klass = import_string(backend or settings.EMAIL_BACKEND)
      51     return klass(fail_silently=fail_silently, **kwds)

 File ~/nicecv/venv/lib/python3.11/site-
 packages/django/utils/module_loading.py:30, in import_string(dotted_path)
      27     raise ImportError("%s doesn't look like a module path" %
 dotted_path) from err
      29 try:
 ---> 30     return cached_import(module_path, class_name)
      31 except AttributeError as err:
      32     raise ImportError(
      33         'Module "%s" does not define a "%s" attribute/class'
      34         % (module_path, class_name)
      35     ) from err

 File ~/nicecv/venv/lib/python3.11/site-
 packages/django/utils/module_loading.py:15, in cached_import(module_path,
 class_name)
       8 def cached_import(module_path, class_name):
       9     # Check whether module is loaded and fully initialized.
      10     if not (
      11         (module := sys.modules.get(module_path))
      12         and (spec := getattr(module, "__spec__", None))
      13         and getattr(spec, "_initializing", False) is False
      14     ):
 ---> 15         module = import_module(module_path)
      16     return getattr(module, class_name)

 File /usr/lib/python3.11/importlib/__init__.py:126, in import_module(name,
 package)
     124             break
     125         level += 1
 --> 126 return _bootstrap._gcd_import(name[level:], package, level)

 File <frozen importlib._bootstrap>:1204, in _gcd_import(name, package,
 level)

 File <frozen importlib._bootstrap>:1176, in _find_and_load(name, import_)

 File <frozen importlib._bootstrap>:1126, in _find_and_load_unlocked(name,
 import_)

 File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f,
 *args, **kwds)

 File <frozen importlib._bootstrap>:1204, in _gcd_import(name, package,
 level)

 File <frozen importlib._bootstrap>:1176, in _find_and_load(name, import_)

 File <frozen importlib._bootstrap>:1140, in _find_and_load_unlocked(name,
 import_)

 ModuleNotFoundError: No module named 'smtp'

 }}}


 Thank you for any help!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34783>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018a07455f2f-0f699050-1c03-4cac-a3b2-19e7152885a8-000000%40eu-central-1.amazonses.com.

Reply via email to