Skip to content

Adds support for Django 6.1 MAILERS - #661

Open
a-musing-moose wants to merge 1 commit into
joke2k:developfrom
a-musing-moose:mailers
Open

a-musing-moose wants to merge 1 commit into
joke2k:developfrom
a-musing-moose:mailers

Conversation

@a-musing-moose

@a-musing-moose a-musing-moose commented Sep 7, 2026 •

Copy link
Copy Markdown

Provides a new mailer/mail_url which parses EMAIL URLs and returns configuration suitable for the new Django 6.1 MAILERS setting.

I've attempted to keep it fairly separate from the existing email URL parsing but to also make it easy to switch across to the new style options for example.

I am also not all the familiar with tox - but I have attempted to add Django 6.1 to the matrix, but may easily have messed something up. tox -e py314-django61 certainly runs cleanly locally. As do the others I have Python versions available for.

Hopefully this is useful - but please let me know if I have missed anything important.

Resolves #606

@codingjoe codingjoe left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nice and clean human code. Love it.

I have one remark: Let's assume not all options are in the URL. How can I inject more options?

@Akay7

Akay7 commented Oct 2, 2026

Copy link
Copy Markdown

Maybe better to merge that rather than waiting for a perfect implementation? Moreover, no specific examples of what needs to be added are provided here.

@a-musing-moose

Copy link
Copy Markdown
Author

Ah, nice and clean human code. Love it.

I have one remake: Let's assume not all options are in the URL. How can I inject more options?

Good suggested @codingjoe, and sorry for the long wait. I have updated my PR with an additional commit. This one introduces an extra_options parameter. This follows the same approach as used in the DB URL parse, it is applied after options extracted from the URL.

Let me know if there is anything else you would like to see refined on this.

@codingjoe codingjoe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that looks promising. I haven't done a full review, since you added a lot of unrelated formatting changes. Ping me, when you need another review.

Comment thread docs/types.rst Outdated
Comment on lines +253 to +270
:py:meth:`~.environ.Env.email_url`, but returns one Django 6.1 ``MAILERS``
entry with ``BACKEND`` and lowercase ``OPTIONS`` keys. The ``mailer`` method
is an alias for ``mailer_url``.

Pass ``extra_options`` to either method to add options that are awkward to
encode in a URL or to override URL-derived values. Extra option keys should
use the lowercase Django mailer option names, and their values are preserved
without casting:

.. code-block:: python

config = env.mailer_url(extra_options={
"use_tls": False,
"custom_option": {"retries": 3},
})

The extra values are merged into ``OPTIONS`` after URL parsing, so they take
precedence over options from the URL.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might I suggest adding a full example including the output?

>>> MAILERS = {"default": env.mailer_url(extra_options={
...  "use_tls": False,
...  "custom_option": {"retries": 3},
...})}
>>> print(MAILERS)
{…}

That might be more descriptive than most of the prose.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good idea, hopefully what I have now added makes things clearer

Comment thread environ/environ.py

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That fails contains a lot of unrelated reformatting; please drop it from your changeset.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooph, sorry - I reconfigured my IDEs auto-formatters recently. Fine for my project, not so much for others. Should be good now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still present in another file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have my act together now. test_env.py is now back to what it should be with just the added tests.

Comment thread tests/test_email.py
Comment on lines +86 to +93
assert Env.mailer_url_config(url) == {
'BACKEND': 'django.core.mail.backends.smtp.EmailBackend',
'OPTIONS': {
'host': 'smtp.example.com',
'timeout': 30,
'use_ssl': 'false',
},
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of just testing against a fixed output, the tests would be more meaningful if you actually import the backend and initialize it. That way, we know the output configuration dictionary is correct.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a tried importing the backend, and passing the options to initialise it, but it opened a bit of a can of worms.

The backend tried to access other Django settings - which failed because Django has not yet been bootrapped. And to bootstrap Django I need a settings file etc. So it gets a bit more complex than I think is worth it here.

I can continue down that rabbit hole if you would like me to, but I suspect the existing tests asserting against dicts might not be a coincidence.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it also doesn't seem to be done on other parsers. While I believe it's a worthwhile improvement, its definitely exceeds the scope. Thanks for giving it a try though 👍

@codingjoe codingjoe left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @a-musing-moose,

please be so kind and review your own changes. You will have reformatting in your changeset.

I'd also recommend adding a deprecation warning for email_url for if Django >= 6.1. That way we can remove the parser once we sunset support for older Django versions.

Thanks for your patience, if you are quick I can do another review on FOSS Friday.

Best
-joe

@a-musing-moose
a-musing-moose force-pushed the mailers branch 3 times, most recently from 03d2a25 to 46f5a52 Compare November 18, 2026 21:29
@a-musing-moose

a-musing-moose commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

Hi @a-musing-moose,

please be so kind and review your own changes. You will have reformatting in your changeset.

I'd also recommend adding a deprecation warning for email_url for if Django >= 6.1. That way we can remove the parser once we sunset support for older Django versions.

Thanks for your patience, if you are quick I can do another review on FOSS Friday.

Best -joe

I am terribly sorry for wasting your time on that round of reviews, and thanks for jumping on it so quickly.

I have reviewer this one and with a little tweaking managed to get tox working locally. Side note: Installing tox-gh-actions seems to break running tox for me with an invalid import. (edit: tox-gh-actions 3.5.1 released in the last few hours resolved this).

The over-zealous reformatting should be gone now and we are back to just my changed. Which now includes a deprecation warning if email_url_config is called when using Django 6.1 or above

Provides a new mailer/mail_url which parses EMAIL URLs and returns configuration suitabler for the new Django 6.1 MAILERS setting.

I've attempted to keep it fairly separate from the existing email URL parsing but to also make it easy to switch across to the new style options for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Django 6.1 EMAIL_PROVIDERS support

3 participants