summaryrefslogtreecommitdiff
path: root/django/core/mail/backends
AgeCommit message (Collapse)Author
2026-06-03Fixed CVE-2026-7666 -- Delayed setting SMTP connection until fully configured.Jake Howard
Thanks Kasper Dupont for the report, and Jacob Walls and Natalia Bidart for reviews.
2026-05-14Refs #36664 -- Updated SMTP EmailBackend tests for Python 3.15.Mike Edmunds
Versions of Python prior to 3.15 would incorrectly encode non-ASCII email addresses using rfc2047, resulting in undeliverable email. The SMTP EmailBackend detects and prevents that (#35713). Python 3.15 fixes that behavior (CPython issue gh-122476). Updated test_rejects_non_ascii_local_part() to feature-detect the fix (in case it is backported) and check for a representative section of the Python error message if so; otherwise test for the SMTP EmailBackend workaround. Updated comments to clarify need and requirement.
2026-05-13Fixed #35514 -- Implemented dictionary-based MAILERS.Mike Edmunds
See DEP 0018. Added: * MAILERS setting. * django.core.mail.mailers dict-like EmailBackend factory. * `using` argument to mail sending APIs. * `sent_using` attribute to mail.outbox messages in locmem backend. * MAILERS in startproject settings template, set to console backend. * AdminLogHandler.using argument. * BrokenLinkEmailsMiddleware.send_mail() method. Updated: * BaseEmailBackend to track the MAILERS alias used to construct it, and to report errors for unknown kwargs (OPTIONS). * EmailBackend implementations to initialize from kwargs (OPTIONS) only when MAILERS is being used. * smtp.EmailBackend to require `host` option and to default `port` option based on SSL/TLS options. * SimpleTestCase setup to substitute the locmem backend for all defined MAILERS configurations. * Django's tests that send mail to define MAILERS. Deprecated: * EMAIL_BACKEND and other backend-related EMAIL_* settings. * mail.get_connection(). * The `connection`, `fail_silently`, `auth_user`, and `auth_password` arguments to mail functions. * The EmailMessage.connection attribute. * BaseEmailBackend support for `fail_silently`. Backends that support fail_silently (SMTP, console, file) now implement it directly. * AdminEmailHandler.email_backend argument. Removed undocumented features without deprecation: * EmailMessage.get_connection() method. (send() now raises an error if a subclass has attempted to override it.) * EmailMessage.send() no longer sets self.connection to the connection used for sending. (It still _uses_ a pre-existing self.connection.) * AdminEmailHandler.connection() method. (Init now raises an error if a subclass has attempted to override it.) Thanks to Natalia Bidart for shepherding DEP 0018 and for extensive reviews and suggestions on the implementation. Thanks to Jacob Rief for the initial implementation and multiple iterations while refining the design. Co-authored-by: Jacob Rief <jacob.rief@gmail.com>
2026-05-06Refs #35514 -- Added error for missing EMAIL_FILE_PATH setting.Mike Edmunds
Replaced TypeError in `os.path.abspath(None)` with ImproperlyConfigured error when settings.EMAIL_FILE_PATH is required but missing.
2025-07-25Fixed #35581 -- Updated django.core.mail to Python's modern email API.Mike Edmunds
- Changed EmailMessage.message() to construct a "modern email API" email.message.EmailMessage and added policy keyword arg. - Added support for modern MIMEPart objects in EmailMessage.attach() (and EmailMessage constructor, EmailMessage.attachments list). - Updated SMTP EmailBackend to use modern email.policy.SMTP. Deprecated: - Attaching MIMEBase objects (replace with MIMEPart) - BadHeaderError (modern email uses ValueError) - SafeMIMEText, SafeMIMEMultipart (unnecessary for modern email) - django.core.mail.forbid_multi_line_headers() (undocumented, but exposed via `__all__` and in wide use) - django.core.mail.message.sanitize_address() (undocumented, but in wide use) Removed without deprecation (all undocumented): - EmailMessage.mixed_subtype - EmailMultiAlternatives.alternative_subtype - Support for setting (undocumented) EmailMessage.encoding property to a legacy email.charset.Charset object Related changes: - Dropped tests for incorrect RFC 2047 encoding of non-ASCII email address localparts. This is specifically prohibited by RFC 2047, and not supported by any known MTA or email client. (Python still mis-applies encoded-word to non-ASCII localparts, but it is a bug that may be fixed in the future.) - Added tests that try to discourage using Python's legacy email APIs in future updates to django.core.mail.
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2023-10-25Fixed #34904 -- Prevented mutating sent emails from outbox in locmem email ↵sindre
backend.
2023-03-14Improved connection clean-up for SMTP backend.Carlton Gibson
2023-03-06Fixed #34386 -- Made SMTP backend load default system root CA certificates ↵Dmitriy Sintsov
by default. Regression in 2848e5d0ce5cf3c31fe87525536093b21d570f69.
2022-11-16Refs #34118 -- Used smtplib's context parameter instead of keyfile and certfile.Mariusz Felisiak
keyfile and certfile parameters were removed in Python 3.12, see https://github.com/python/cpython/commit/ef0e72b31d22f780d3a165d7d0471806061fe380
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2019-11-06Refs #29983 -- Added pathlib.Path support to the file email backend.Jon Dufresne
2019-01-31Fixed #30147 -- Simplified directory creation with os.makedirs(..., ↵Jon Dufresne
exist_ok=True).
2019-01-28Fixed #30137 -- Replaced OSError aliases with the canonical OSError.Jon Dufresne
Used more specific errors (e.g. FileExistsError) as appropriate.
2018-12-26Fixed #30058 -- Made SMTP EmailBackend.send_messages() return 0 for ↵Denis Stebunov
empty/error cases.
2017-11-06Fixed #28776 -- Fixed a/an/and typos in docs and comments.Дилян Палаузов
2017-06-01Sorted imports per isort 4.2.9.Tim Graham
2017-02-21Refs #27656 -- Updated django.core docstring verbs according to PEP 257.Anton Samarchyan
2017-02-01Refs #23919 -- Replaced kwargs.pop() with keyword-only arguments.Vytis Banaitis
2017-01-25Refs #23919 -- Replaced super(ClassName, self) with super().chillaranand
2017-01-20Refs #23919 -- Removed unneeded force_str callsClaude Paroz
2017-01-19Refs #23919 -- Stopped inheriting from object to define new style classes.Simon Charette
2017-01-18Refs #23919 -- Removed six.<various>_types usageClaude Paroz
Thanks Tim Graham and Simon Charette for the reviews.
2017-01-18Refs #23919 -- Removed six.PY2/PY3 usageClaude Paroz
Thanks Tim Graham for the review.
2016-12-23Refs #26487 -- Removed unneeded ehlo() calls in SMTP backend.Tim Graham
starttls(), login(), and other connection methods already call the method as needed.
2016-10-21Fixed #27368 -- Modifed BaseEmailBackend.__enter__() to close the connection ↵Jon Dufresne
if an exception occurs. Fixes unclosed socket ResourceWarning in mail test. Thanks Claude Paroz for the review.
2016-10-05Removed unused variable in django/core/mail/backends/smtp.py.Tim Graham
2016-09-27Fixed #27210 -- Allowed SMTPBackend to fail silently on a socket connection ↵Vesteinn Snaebjarnarson
error.
2016-09-21Fixed #26210 -- Prevented SMTP backend from trying to send mail after a ↵levental
connection failure.
2016-08-31Fixed #27131 -- Passed proper string type to SMTP connection loginClaude Paroz
Passing an Unicode string on Python 2 was crashing the connection. Thanks slavugan@gmail.com for the report, and Tim Graham for the review.
2016-08-08Fixed #27036 -- Made locmem email backend's send_messages() accept generators.Antoine Fontaine
2016-05-06Fixed #25986 -- Fixed crash sending email with non-ASCII in local part of ↵Sergei Maertens
the address. On Python 3, sending emails failed for addresses containing non-ASCII characters due to the usage of the legacy Python email.utils.formataddr() function. This is fixed by using the proper Address object on Python 3.
2015-02-06Sorted imports with isort; refs #23860.Tim Graham
2014-10-12Fixed #23063 -- Convert \n and \r to \r\n when using the SMTP backend as per ↵Florian Apolloner
RFC.
2014-09-13Fixed #23461 -- Added EMAIL_TIMEOUT settingJosé Padilla
2014-09-10Fixed #20743 -- Added support for keyfile/certfile in SMTP connections.Andi Albrecht
Thanks jwmayfield, serg.partizan, and Wojciech Banaś for work on the patch.
2014-09-05Limited lines to 119 characters in django/Tim Graham
refs #23395.
2014-03-31Fixed #22327 -- Turned BaseEmailBackend into a context managerDaniel Neuhäuser
Changed the BaseEmailBackend to allow usage as context manager to open and close connections.
2014-01-12Undelete the `return True` removed in 4e0a2fe.Marc Tamlyn
This is quite important otherwise we don't close our connections to the SMTP server.
2013-12-30Decode mails using the message encoding.Florian Apolloner
2013-12-30Changed console and filebackend to use msg.as_bytes to output the data as it ↵Florian Apolloner
would get send via smtp.
2013-12-28Introduced as_bytes for SafeMIMEText (and other SafeMIME-classes).Florian Apolloner
This is to provide a consistent interface (namely bytes) for the smtp backend which after all sends bytes over the wire; encoding with as_string yields different results since mails as unicode are not really specified. as_string stays for backwardscompatibilty mostly and some debug outputs. But keep in mind that the output doesn't match as_bytes!
2013-11-02More attacking E302 violatorsAlex Gaynor
2013-10-25Undelete the login() call inadvertantly removed in 4e0a2fe59cClaude Paroz
Refs #21271.
2013-10-24Fixed #21271 -- Added timeout parameter to SMTP EmailBackend.SusanTan
Thanks Tobias McNulty and Tim Graham for discussions and code review. Thanks Andre Cruz the suggestion and initial patch.
2013-10-24Start attacking E231 violationsAlex Gaynor
2013-10-10Whitespace cleanup.Tim Graham
* Removed trailing whitespace. * Added newline to EOF if missing. * Removed blank lines at EOF. * Removed some stray tabs.
2013-10-05Fixed #21189: Cleaned up usage of bare except clauses.Baptiste Mispelon
Thanks to berkerpeksag for the report and to claudep for the review.
2013-09-10Fixed #20841 -- Added messages to NotImplementedErrorsGregor MacGregor
Thanks joseph at vertstudios.com for the suggestion.
2013-07-11Fixed #17471 -- Added smtplib.SMTP_SSL connection option for SMTP backendClaude Paroz
Thanks dj.facebook at gmail.com for the report and initial patch and Areski Belaid and senko for improvements.