django/django · error · TypeError

fail_silently cannot be used with a connection. Pass fail_si

Error message

fail_silently cannot be used with a connection. Pass fail_silently to get_connection() instead.

What it means

EmailMessage.send() (django/core/mail/message.py:410) raises TypeError if you pass fail_silently=True while the message already carries an explicit connection (self._connection). fail_silently is a property of the connection, not the message, so combining the two is contradictory and ambiguous.

Source

Thrown at django/core/mail/message.py:410

        #   return mailer.send_messages([self])

        from django.core import mail

        if fail_silently:
            warn_about_external_use(FAIL_SILENTLY_ARG_WARNING, RemovedInDjango70Warning)
        if hasattr(self, "get_connection"):
            raise AttributeError(
                "EmailMessage no longer supports the undocumented "
                "get_connection() method."
            )

        if using is not None:
            report_using_incompatibility(self._connection, fail_silently)
            connection = mail.mailers[using]
        elif self._connection:
            connection = self._connection
            if fail_silently:
                raise TypeError(
                    "fail_silently cannot be used with a connection. "
                    "Pass fail_silently to get_connection() instead."
                )
        else:
            connection = mail.get_connection(fail_silently=fail_silently)

        return connection.send_messages([self])

    def attach(self, filename=None, content=None, mimetype=None):
        """
        Attach a file with the given filename and content. The filename can
        be omitted and the mimetype is guessed, if not provided.

        If the first parameter is a MIMEBase subclass, insert it directly
        into the resulting message attachments.

        For a text/* mimetype (guessed or specified), when a bytes object is
        specified as content, decode it as UTF-8. If that fails, set the

View on GitHub (pinned to ae25a40be0)

Solutions

  1. Pass fail_silently when opening the connection: get_connection(fail_silently=True).
  2. Drop fail_silently from send() and let the existing connection control error behavior.
  3. Migrate to the new mailers API (using= alias) where fail_silently is configured on the mailer.

Example fix

// before
conn = get_connection()
msg = EmailMessage(connection=conn)
msg.send(fail_silently=True)
// after
conn = get_connection(fail_silently=True)
msg = EmailMessage(connection=conn)
msg.send()
Defensive patterns

Strategy: validation

Validate before calling

def send_safely(msg, fail_silently=False):
    if fail_silently and getattr(msg, "_connection", None) is not None:
        raise TypeError(
            "fail_silently cannot be combined with an explicit connection; "
            "open the connection with fail_silently instead."
        )
    return msg.send(fail_silently=fail_silently)

Prevention

When it happens

Trigger: msg = EmailMessage(connection=conn); msg.send(fail_silently=True) — using is None, self._connection is set, and fail_silently is true, reaching the raise at line 410.

Common situations: Pre-creating a connection with custom backend settings then trying to make sending fault-tolerant via the message; upgrading code that mixed the two semantics.

Related errors


AI-assisted analysis of django/django@ae25a40be0 (2026-08-06). Data as JSON: /api/errors/bf431ac57323dd75. Report an issue: GitHub.