Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error sending e-mail with smtp backend when using python 3.12 and django 4.1.x #41

Open
pierryangelo opened this issue Apr 16, 2023 · 4 comments

Comments

@pierryangelo
Copy link

No description provided.

@pierryangelo
Copy link
Author

In chapter 2, page 68, using the recommended version of Django by the book (exactly) I could't send e-mail via gmail account. The traceback error was this:

File "/home/pierry/django/my_env/lib/python3.12/site-packages/django/core/mail/message.py", line 298, in send
    return self.get_connection(fail_silently).send_messages([self])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pierry/django/my_env/lib/python3.12/site-packages/django/core/mail/backends/smtp.py", line 124, in send_messages
    new_conn_created = self.open()
                       ^^^^^^^^^^^
  File "/home/pierry/django/my_env/lib/python3.12/site-packages/django/core/mail/backends/smtp.py", line 87, in open
    self.connection.starttls(
TypeError: SMTP.starttls() got an unexpected keyword argument 'keyfile'
>>> send_mail('Django mail', 'This e-mail was sent with Django', '[email protected]', ['[email protected]'], fail_silently=False)

After searching, I discovered that this was an issue django/django@2848e5d.
(keyfile and certfile parameters were removed in Python 3.12)
To solve this, you must install Django 4.2.x or copy the https://github.com/django/django/blob/main/django/core/mail/backends/smtp.py to your local django installation replacing the original 4.1.x file.

I did this and it worked, so I could send the e-mail following the book example.

@pierryangelo pierryangelo changed the title Error sending e-mail with backend s Error sending e-mail with smtp backend when using python 3.12 and django 4.1.x Apr 16, 2023
@roshnirajak
Copy link

It worked for me too, I'm using django 4.1.13 (copying the file worked). Thanks.

@LuizMateuss
Copy link

I downgraded my python version and it worked too

@martin-iturralde
Copy link

I downgraded my python version and it worked too

From which version to what version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants