﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37540	send_mail() can ignore fail_silently=False with a legacy EMAIL_BACKEND	Cleisson	Cleisson	"On Django 6.1, `send_mail()` can return zero instead of raising a delivery error when a project still uses `EMAIL_BACKEND`. This happens with a custom backend whose constructor defaults to `fail_silently=True`. Both omitting the argument to `send_mail()` and passing `fail_silently=False` explicitly should let the exception reach the caller.

Save this as `mail_repro.py` and run `python mail_repro.py` with Django installed. The backend simulates a failed delivery without contacting a mail server.

{{{#!python
from django.conf import settings
from django.core.mail import send_mail
from django.core.mail.backends.base import BaseEmailBackend

settings.configure(EMAIL_BACKEND=""__main__.Backend"")


class Backend(BaseEmailBackend):
    def __init__(self, *, fail_silently=True, **kwargs):
        super().__init__(**kwargs)
        self.fail_silently = fail_silently

    def send_messages(self, messages):
        if self.fail_silently:
            return 0
        raise OSError(""connection refused"")


for options in ({}, {""fail_silently"": False}, {""fail_silently"": True}):
    try:
        result = send_mail(
            ""Subject"", ""Body"", ""a@example.com"", [""b@example.com""], **options
        )
    except OSError as error:
        result = f""OSError: {error}""
    print(options, result)
}}}

On Django 6.0.10 the first two calls raise the simulated error.

{{{
{} OSError: connection refused
{'fail_silently': False} OSError: connection refused
{'fail_silently': True} 0
}}}

On 6.1, 6.1.3, and `main` at `f0e7bd9088`, all three calls return zero. An application that catches delivery exceptions can miss the failure.

This started with [https://github.com/django/django/commit/0f581cd29d42d1b5ed1dafb67794c2f3ce6705c9 0f581cd29d] (#35514). With `EMAIL_BACKEND` set and `MAILERS` unset, `get_connection()` now passes the flag to the backend constructor only when it is true. Omitting the keyword leaves this backend's own default in effect. In #36894 the caller supplies an existing `connection`. This example lets Django construct the backend.

A patch and regression test are on my fork. With the patch, the script gives the 6.0.10 output again.

OpenAI Codex (GPT-6.2 Astra and Sol) helped investigate the regression, prepare the patch and tests and run the example."	Bug	assigned	Core (Mail)	6.1	Release blocker				Unreviewed	0	0	0	0	0	0
