Repository navigation
Send queued mail through MAILERS on Django 6.1 - #191
Open
phedoreanu wants to merge 1 commit into
Open
phedoreanu wants to merge 1 commit into
phedoreanu wants to merge 1 commit into
Conversation
Django 6.1 deprecates the EMAIL_* settings in favour of MAILERS. Once a project defines MAILERS, send_all() broke in two places: it read settings.EMAIL_BACKEND, which is no longer available, and it called get_connection(backend=...), which Django rejects with MAILERS. DbBackend now takes a "using" option that names the mailer which does the real sending, as DEP 18 recommends for wrapper backends. send_all() reads it from the settings and sends through mailers[using]. Without a DbBackend mailer the default mailer delivers. Projects that still use EMAIL_BACKEND and MAILER_EMAIL_BACKEND behave as before. The message is now handed to the connection with send_messages() rather than by setting email.connection, which is deprecated too. A message whose recipients are all on the don't-send list is still skipped, as EmailMessage.send() did. Refs pinax#190
|
Thx! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Django 6.1 deprecates the
EMAIL_*settings in favour ofMAILERS. As soon as a project definesMAILERS,send_all()stops working:settings.EMAIL_BACKEND, which raisesAttributeErrorwhenMAILERSis definedget_connection(backend=...), which raisesRuntimeError: get_connection(backend, ...) is not supported with MAILERS.So a project on 6.1 has to keep the deprecated settings to keep its queue moving.
This follows the upgrade path for wrapper backends from DEP 18 that #190 points to.
DbBackendtakes ausingoption naming the mailer that does the real sending:send_all()readsusingfrom the settings and sends throughmailers[using]. A few decisions worth a look:DbBackendmailers must share oneusing. Different values raiseImproperlyConfigured. Supporting them properly would need a column onMessage, which I left out.MAILERSdefined but noDbBackendmailer (mail queued withmailer.send_mail()and friends), the default mailer delivers.usingpointing at anotherDbBackendmailer raises, like the existingEMAIL_BACKEND/MAILER_EMAIL_BACKENDloop check.MAILER_EMAIL_BACKENDis ignored whenMAILERSis defined. WithoutMAILERSnothing changes, on any Django version.send_all()also stops assigningemail.connection, which 6.1 deprecates, and callsconnection.send_messages([email])instead.EmailMessage.send()used to skip a message with no recipients, which is what makes the don't-send list work, so that check is kept explicitly (test_blacklisted_emailscovers it).Tested with pytest on Django 6.1.3 and 5.2.13 (Python 3.14). The new tests are skipped below 6.1. I didn't add a 6.1 env to tox or the workflow; happy to if you want it in this PR.
Refs #190