coderedcorp / coderedcorp/cr-sendmail-django
Emails fail with bad keyword argument `linesep` in Django 6.0+
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
I recently noticed that my site is no longer sending e-mails when using this backend, and the logs show it’s because of the `linesep` kwarg on line 48 of `cr_sendmail/backends.py`: https://github.com/coderedcorp/cr-sendmail-django/blob/84bcce056e21a773daa2ce37421398de2588e068/cr_sendmail/backends.py#L43-L48
For example, when trying to do a password reset from the login screen, I see the following in logs:
```
2026-09-02 21:29:33,666 ERROR [django.contrib.auth] Failed to send password reset email to 1
Traceback (most recent call last):
File "/usr/local/tenantlib/lib/python3.13/site-packages/django/contrib/auth/forms.py", line 417, in send_mail
email_message.send()
~~~~~~~~~~~~~~~~~~^^
File "/usr/local/tenantlib/lib/python3.13/site-packages/django/core/mail/message.py", line 358, in send
return self.get_connection(fail_silently).send_messages([self])
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/cr_sendmail/backends.py", line 27, in send_messages
if self._send(m):
~~~~~~~~~~^^^
File "/usr/local/lib/python3.13/site-packages/cr_sendmail/backends.py", line 55, in _send
raise err
File "/usr/local/lib/python3.13/site-packages/cr_sendmail/backends.py", line 48, in _send
stdout, stderr = p.communicate(input=m.as_bytes(linesep="\r\n"))
~~~~~~~~~~^^^^^^^^^^^^^^^^
TypeError: Message.as_bytes() got an unexpected keyword argument 'linesep'
```
This definitely worked more recently than the relevant lines in this package have changed, so my first guess as to the problem is that this is a result of upgrading to Django 6. The site is currently running:
- Django 6.0.7
- Wagtail 7.4.2
AFAICT, the cause here is that this code calls `m = email_message.message()`, where `email_message` is a Django `EmailMessage`. In Django 5.1, `.message()` returned a `SafeMIMEText`, which has a `linesep` kwarg on its `as_bytes()` method: https://github.com/django/django/blob/stable/5.1.x/django/core/mail/message.py#L261-L263
But in Django 6.0, it standard returning `email.message.EmailMessage` from the Python standard library, which [does not have a `linesep` kwarg on `as_bytes()`](https://docs.python.org/3.13/library/email.message.html#email.message.EmailMessage.as_bytes): https://github.com/django/django/blob/6.0/django/core/mail/message.py#L315-L316
(More on this in the Django release notes: https://docs.djangoproject.com/en/6.1/releases/6.0/#adoption-of-python-s-modern-email-api, though obviously it was not accurate for them to say `email.message.EmailMessage` “supports the same API as the previous `SafeMIMEText`.”)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in cr_sendmail/backends.py around line 48 and inspect how Django’s EmailMessage is serialized before being passed to sendmail. Reproduce the password-reset email failure under Django 6.0, then verify that sending succeeds while preserving compatibility with the earlier SafeMIMEText behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 82/100