a custom backend for testing from django core mail backends base import baseemailbackend class emailbackendbaseemailbackend def initself args kwargs super initargs kwargs self testoutbox def sendmessagesself emailmessages messages are stored in an instance variable for testing self testoutbox extendemailmessages return lenemailmessages messages are stored in an instance variable for testing
from django.core.mail.backends.base import BaseEmailBackend


class EmailBackend(BaseEmailBackend):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.test_outbox = []

    def send_messages(self, email_messages):
        
        self.test_outbox.extend(email_messages)
        return len(email_messages)