{"record":{"id":"75e1fe74e493510d","repo":"django/django","slug":"subclasses-of-baseemailbackend-must-override-send","errorCode":null,"errorMessage":"subclasses of BaseEmailBackend must override send_messages() method","messagePattern":"subclasses of BaseEmailBackend must override send_messages\\(\\) method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"django/core/mail/backends/base.py","lineNumber":124,"sourceCode":"        pass\n\n    def __enter__(self):\n        try:\n            self.open()\n        except Exception:\n            self.close()\n            raise\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        self.close()\n\n    def send_messages(self, email_messages):\n        \"\"\"\n        Send one or more EmailMessage objects and return the number of email\n        messages sent.\n        \"\"\"\n        raise NotImplementedError(\n            \"subclasses of BaseEmailBackend must override send_messages() method\"\n        )\n","sourceCodeStart":106,"sourceCodeEnd":127,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/mail/backends/base.py#L106-L127","documentation":"Raised as a NotImplementedError by BaseEmailBackend.send_messages() because send_messages is the abstract contract of an email backend: it must be overridden by every concrete subclass to actually deliver EmailMessage objects. Calling it on the base class (or a subclass that forgot to override it) yields this error.","triggerScenarios":"Instantiating BaseEmailBackend directly and calling send_messages; a custom backend subclass whose author forgot to define send_messages; a backend class meant only as a mixin that was used directly.","commonSituations":"Writing a custom email backend and missing the send_messages implementation; instantiating the wrong (base) class; testing scaffolding that uses the base class.","solutions":["Override send_messages(self, email_messages) in your backend subclass, returning the number of messages sent.","If you didn't intend to write a backend, use a built-in backend (smtp, console, file, locmem, dummy) via EMAIL_BACKEND or MAILERS.","Ensure any abstract/mixin backend base is subclassed before use."],"exampleFix":"// before\nclass MyBackend(BaseEmailBackend):\n    pass  // forgot send_messages\n// after\nclass MyBackend(BaseEmailBackend):\n    def send_messages(self, email_messages):\n        sent = 0\n        for msg in email_messages:\n            self._deliver(msg); sent += 1\n        return sent","handlingStrategy":"type-guard","validationCode":"from django.core.mail.backends.base import BaseEmailBackend\ndef assert_overrides_send_messages(backend_cls):\n    if backend_cls.send_messages is BaseEmailBackend.send_messages:\n        raise NotImplementedError('subclass must override send_messages')\n    return backend_cls","typeGuard":"from django.core.mail.backends.base import BaseEmailBackend\ndef backend_implements_send_messages(backend_cls) -> bool:\n    return backend_cls.send_messages is not BaseEmailBackend.send_messages\n","tryCatchPattern":null,"preventionTips":["Always implement send_messages(self, email_messages) on custom backends.","Add an abstract test that instantiates each backend and asserts send_messages is overridden.","Prefer built-in backends unless you truly need a custom one."],"tags":["email","backend","not-implemented","django"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}