Skip to main content

EmailBackend

This class provides an email backend implementation that writes email messages to a specified stream, defaulting to standard output. It ensures thread-safe operations using a reentrant lock when processing multiple messages. The class handles message encoding and formatting, appending a separator between each message written to the stream.

Attributes

AttributeTypeDescription
streamfile-like object = sys.stdoutThe output destination where email messages are written, defaulting to standard output.
_lockthreading.RLockA reentrant threading lock used to ensure thread-safe access to the output stream during message writing.
fail_silentlyboolean = FalseA boolean flag that determines whether exceptions during the email sending process are suppressed or raised.

Constructor

Signature

def EmailBackend(
fail_silently: boolean = False,
**kwargs: dict
) - > null

Parameters

NameTypeDescription
fail_silentlyboolean = FalseWhether to suppress exceptions during email sending.
**kwargsdictAdditional keyword arguments, including an optional 'stream' for output.

Methods


write_message()

@classmethod
def write_message(
message: [EmailMessage](../../message/emailmessage.md?sid=django_core_mail_message_emailmessage)
) - > null

Formats a single email message as a string and writes it to the configured output stream followed by a separator line.

Parameters

NameTypeDescription
message[EmailMessage](../../message/emailmessage.md?sid=django_core_mail_message_emailmessage)The email message instance to be serialized and written to the stream

Returns

TypeDescription
nullNone

send_messages()

@classmethod
def send_messages(
email_messages: list
) - > int

Write all messages to the stream in a thread-safe way.

Parameters

NameTypeDescription
email_messageslistA collection of EmailMessage instances to be dispatched to the output stream

Returns

TypeDescription
intThe total number of email messages successfully processed and written to the stream