1"""Base email backend class.""" 2 3from__future__importannotations 4 5fromabcimportABC,abstractmethod 6fromtypingimportTYPE_CHECKING,Any 7 8ifTYPE_CHECKING: 9fromtypesimportTracebackType1011from..messageimportEmailMessage121314classBaseEmailBackend(ABC):15"""16 Base class for email backend implementations.1718 Subclasses must at least overwrite send_messages().1920 open() and close() can be called indirectly by using a backend object as a21 context manager:2223 with backend as connection:24 # do something with connection25 pass26 """2728def__init__(self,fail_silently:bool=False,**kwargs:Any)->None:29self.fail_silently=fail_silently3031defopen(self)->bool|None:32"""33 Open a network connection.3435 This method can be overwritten by backend implementations to36 open a network connection.3738 It's up to the backend implementation to track the status of39 a network connection if it's needed by the backend.4041 This method can be called by applications to force a single42 network connection to be used when sending mails. See the43 send_messages() method of the SMTP backend for a reference44 implementation.4546 The default implementation does nothing.47 """48pass4950defclose(self)->None:51"""Close a network connection."""52pass5354def__enter__(self)->BaseEmailBackend:55try:56self.open()57exceptException:58self.close()59raise60returnself6162def__exit__(63self,64exc_type:type[BaseException]|None,65exc_value:BaseException|None,66traceback:TracebackType|None,67)->None:68self.close()6970@abstractmethod71defsend_messages(self,email_messages:list[EmailMessage])->int:72"""73 Send one or more EmailMessage objects and return the number of email74 messages sent.75 """76...