summaryrefslogtreecommitdiff
path: root/tests/mail
AgeCommit message (Collapse)Author
2026-04-11Fixed #36953 -- Split EmailBackend tests to separate file.Mike Edmunds
Moved tests for specific email backends from tests/mail/tests.py to test_backends.py to reduce file size and discourage adding non-backend-specific tests to BaseEmailBackendTests.
2026-04-11Refs #36953 -- Moved non-backend-dependent BaseEmailBackendTests.Mike Edmunds
Relocated BaseEmailBackendTests that are _not_ dependent on the email backend. - In general, moved test cases to EmailMessageTests or SendMailTests as appropriate, and changed them to work with the testing outbox. - Replaced BaseEmailBackendTests.test_send_verbose_name() with EmailMessageTests.test_unicode_display_name_in_from_email(). (EmailMessageTests.test_address_header_handling() also partly covers the behavior, as well as Python's own message serialization tests.) - Removed BaseEmailBackendTests.test_message_cc_header(), which was already covered by EmailMessageTests.test_cc*() (and Python's own message serialization tests). - Replaced BaseEmailBackendTests.test_idn_send() with EmailMessageTests.test_idn_addresses() to cover from_email and cc. (EmailMessageTests.test_address_header_handling() already covered to.) - Removed BaseEmailBackendTests.test_recipient_without_domain(), which was partly covered by EmailMessageTests.test_localpart_only_address(). Updated the latter to cover a localpart-only from_email. - Updated docstrings and comments to clarify a few tests that _do_ depend on the email backend.
2026-04-11Refs #36953 -- Split apart catchall MailTests.Mike Edmunds
Replaced large MailTests class with smaller classes focused on specific django.core.mail APIs: - EmailMessageTests: covering EmailMessage and EmailMultiAlternatives classes (the bulk of the former MailTests cases). - SendMailTests, SendMassMailTests, MailAdminsAndManagersTests: covering the function-based mail APIs. - GetConnectionTests: covering get_connection(). - DeprecatedInternalsTests: covering deprecated internal methods used in deprecated functionality. - DummyBackendTests: covering the dummy EmailBackend. In the process, moved the two cases from MailTimeZoneTests into the new EmailMessageTests, as they related to EmailMessage Date headers.
2026-04-11Refs #36953 -- Split compound mail tests.Mike Edmunds
Broke apart independent cases in mail tests using subTest() or separate methods.
2026-04-11Refs #36953 -- Removed unnecessary overrides from mail tests.Mike Edmunds
Django automatically substitutes the locmem EmailBackend during tests, and SimpleTestCase empties mail.outbox before each test.
2026-03-16Fixed #36894 -- Added TypeError for conflicting arguments in mail APIs.Praful Gulani
A TypeError is now raised if fail_silently=True, auth_user, or auth_password are provided along a connection. Updated AdminEmailHandler in django.utils.log to remove redundant fail_silently=True. Thanks Mike Edmunds for the report and Jacob Tyler Walls for the review.
2026-01-18Applied Black's 2026 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/26.1.0
2025-10-17Refs #35844 -- Doc'd Python 3.14 compatibility.Mariusz Felisiak
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.
2025-07-25Refs #35581 -- Added missing test for lazy email headers.Mike Edmunds
EmailMessage is intended to support lazy strings in any header field (via coercion to `str` in forbid_multi_line_headers() called from SafeMIMEMessage/Text/Multipart.__setitem__).
2025-07-23Refs #36500 -- Corrected rewrapped long lines fixed via a script.Mike Edmunds
Manually reformatted some comments and docstrings where autofix_w505.py changed the meaning of the formatting.
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
2025-07-17Fixed #36163 -- Deprecated most positional arguments in django.core.mail.Mike Edmunds
In public mail APIs, changed less frequently used parameters from keyword-or-positional to keyword-only, emitting a warning during the required deprecation period.
2025-07-16Refs #35581 -- Added workaround for Python bug in mail tests.Mike Edmunds
See python/cpython#128110.
2025-07-16Refs #35581 -- Reduced implementation dependencies in mail tests.Mike Edmunds
Updated mail tests in preparation for migrating from Python's legacy to modern email API. The updated tests will pass with either Python API, and focus on desired outcomes (e.g., that a message with non-ASCII content parses accurately at the receiving end) rather than specific implementation details (e.g., where rfc2047 encoded-words are split). In a few cases that are still implementation dependent, added comments identifying behavior specific to the legacy email API and expected to change under the modern one. Added comments identifying tests that cover internal functions planned for deprecation, and (where meaningful) added similar tests to verify the equivalent behavior in non-deprecated features. Removed obsolete tests left over from Python 2.
2025-06-26Fixed #36478 -- Fixed inconsistent mail attachment handling.Mike Edmunds
Fixed an inconsistency between EmailMessage.attach() and .attachments when attaching bytes content with a text/* mimetype. The attach() function decodes UTF-8 bytes if possible and otherwise changes the mimetype to application/octet-stream to preserve the content's unknown encoding (refs #27007). Providing equivalent content directly in EmailMessage.attachments did not apply the same logic, leading to an "AttributeError: 'bytes' object has no attribute 'encode'" in SafeMIMEText.set_payload(). Updated EmailMessage._create_mime_attachment() to match attach()'s handling for text/* mimetypes with bytes content. Updated test cases to accurately cover behavior on both paths.
2025-04-24Fixed #36309 -- Made email alternatives and attachments pickleable.nessita
Regression in aba0e541caaa086f183197eaaca0ac20a730bbe4 and in d5bebc1c26d4c0ec9eaa057aefc5b38649c0ba3b. Thanks Florent Messa for the report, and Jake Howard and Claude Paroz for the review.
2025-04-09Refs #35581 -- Updated mail tests to include trailing newlines.Mike Edmunds
Python's modern email API will force a trailing newline onto all text/* bodies and attachments. Updated mail tests to include (and check for) the newline while still using the legacy email API. See https://github.com/python/cpython/issues/121515 which reasons that, apart from artificial test cases, most text content already ends in a newline. If it doesn't, adding one won't change the meaning.
2025-03-21Fixed #36138 -- Changed ADMINS and MANAGERS settings to lists of strings.Mike Edmunds
Previously, the ADMINS and MANAGERS settings were lists of (name, address) tuples (where the name had been unused). Deprecated use of tuples. Updated settings value sanity checks, and changed from ValueError to ImproperlyConfigured.
2025-03-18Refs #36138 -- Improved tests for mail_admins() and mail_managers().Mike Edmunds
- Separated MailTests.test_connection_arg test cases. - Expanded test cases for incorrect values of ADMINS/MANAGERS settings. - Added test case verifying correct values of ADMINS/MANAGERS settings.
2025-01-31Fixed #36119 -- Fixed UnicodeEncodeError when attaching a file with 8bit ↵greg
Content-Transfer-Encoding.
2025-01-20Fixed #36005 -- Dropped support for Python 3.10 and 3.11.Mariusz Felisiak
2024-12-03Refs #35581 -- Added tests for email parameters, attachments, MIME ↵Mike Edmunds
structure, bcc header, encoding and sending.
2024-12-03Refs #35581 -- Used modern email parser and helpers in mail tests.Mike Edmunds
- Used modern email API (policy.default) for tests that reparse generated messages, and switched to modern accessors where helpful. - Split get_raw_attachments() helper out of get_decoded_attachments(), and used modern iter_attachments() to avoid finding nested attachments in attached message/* emails. - Stopped using legacy parseaddr.
2024-12-03Refs #35581 -- Improved reporting for failing tests in mail tests.Mike Edmunds
- Converted HeadersCheckMixin to MailTestsMixin for all shared helpers: - Hoisted assertStartsWith() from BaseEmailBackendTests. - Added matching assertEndsWith(). - Hoisted get_decoded_attachments() from MailTests. - Improved failure reporting in assertMessageHasHeaders(). - Used unittest subTest() to improve handling of compound test cases. - Replaced `assertTrue(test on string)` with custom assertions, so that failure reporting is more informative than `True != False`.
2024-10-29Refs #35581 -- Reduced boilerplate in mail tests.Mike Edmunds
2024-10-29Refs #35581 -- Identified mail tests that check for Python 2 behavior.Mike Edmunds
This also removed a duplicate CTE case (that used to be distinct in Python 2).
2024-10-29Refs #35581 -- Verified attachments in the generated message in mail tests.Mike Edmunds
This also removed send() calls, as this doesn't check the serialized content, and the backend tests cover sending.
2024-10-29Refs #35581 -- Clarified some test names and comments in mail tests.Mike Edmunds
2024-09-03Fixed CVE-2024-45231 -- Avoided server error on password reset when email ↵Natalia
sending fails. On successful submission of a password reset request, an email is sent to the accounts known to the system. If sending this email fails (due to email backend misconfiguration, service provider outage, network issues, etc.), an attacker might exploit this by detecting which password reset requests succeed and which ones generate a 500 error response. Thanks to Thibaut Spriet for the report, and to Mariusz Felisiak, Adam Johnson, and Sarah Boyce for the reviews.
2024-08-05Refs #35537 -- Improved documentation and test coverage for email ↵Jake Howard
attachments and alternatives.
2024-07-11Fixed #35033, Refs #28912 -- Fixed repeated headers in EmailMessage.Mike Edmunds
Fixed a regression which would cause multiple To, Cc, and Reply-To headers in the result of EmailMessage.message() if values were supplied for both to/cc/reply_to and the corresponding extra_headers fields. Updated related tests to check the generated message() has exactly one of each expected header using get_all(). Regression in b03d5002955256c4b3ed7cfae5150eb79c0eb97e.
2024-06-21Fixed #35528 -- Added EmailMultiAlternatives.body_contains() helper method.Ronny Vedrilla
2024-06-20Fixed #35537 -- Changed EmailMessage.attachments and ↵Jake Howard
EmailMultiAlternatives.alternatives to use namedtuples. This makes it more descriptive to pull out the named fields.
2024-06-14Fixed mail.tests.MailTests.test_backend_arg() test on Python 3.13+.Mariusz Felisiak
There is no point in asserting Python error messages.
2024-04-10Refs #35361 -- Added test for Email line length checks when dealing with ↵Natalia
surrogate pairs. Refs #33173, #34118 and #34900.
2024-01-26Applied Black's 2024 stable style.Mariusz Felisiak
https://github.com/psf/black/releases/tag/24.1.0
2024-01-24Added test for the sendtestemail command when no recipients are given.Baptiste Mispelon
2024-01-04Used enterClassContext() where appropriate.Mariusz Felisiak
2023-12-31Used addCleanup() in tests where appropriate.Mariusz Felisiak
2023-10-25Fixed #34904 -- Prevented mutating sent emails from outbox in locmem email ↵sindre
backend.
2023-07-17Refs #34118 -- Improved sanitize_address() error message for tuple with ↵Mariusz Felisiak
empty strings.
2022-11-10Updated documentation and comments for RFC updates.Nick Pope
- Updated references to RFC 1123 to RFC 5322 - Only partial as RFC 5322 sort of sub-references RFC 1123. - Updated references to RFC 2388 to RFC 7578 - Except RFC 2388 Section 5.3 which has no equivalent. - Updated references to RFC 2396 to RFC 3986 - Updated references to RFC 2616 to RFC 9110 - Updated references to RFC 3066 to RFC 5646 - Updated references to RFC 7230 to RFC 9112 - Updated references to RFC 7231 to RFC 9110 - Updated references to RFC 7232 to RFC 9110 - Updated references to RFC 7234 to RFC 9111 - Tidied up style of text when referring to RFC documents
2022-02-19Refs #33173 -- Fixed MailTests.test_backend_arg() on Windows and Python 3.11+.David Smith
2022-02-07Refs #33476 -- Refactored code to strictly match 88 characters line length.Mariusz Felisiak
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2021-10-15Refs #32074 -- Removed usage of deprecated asyncore and smtpd modules.Mariusz Felisiak
asyncore and smtpd modules were deprecated in Python 3.10.
2021-10-14Refs #27131 -- Removed SMTPBackendTests.test_server_login().Mariusz Felisiak
test_server_login() was a regression test for a crash when passing Unicode strings to SMTP server using CRAM-MD5 method on Python 2. Python 2 is no longer supported and test_server_login() passes even without FakeSMTPChannel.smtp_AUTH() because smtplib.SMTPAuthenticationError is raised when AUTH is not implemented.
2021-06-04Refs #32355 -- Used addClassCleanup() in tests.Mariusz Felisiak
Inspired by Adam Johnson talk on DjangoCon Europe 2021.
2021-03-19Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core.Daniyal