Reference

Configuration

Configure MailingKit with environment variables through MailingKit.from_env(), with constructor arguments, or both. Keyword arguments always win over the environment.

Environment variables

Every variable uses the MAILINGKIT_ prefix so it cannot collide with other libraries' MAIL_* settings. Blank values count as unset.

VariableMeaningDefault
MAILINGKIT_PROVIDERconsole, file, memory, smtp, resend, or a registered pluginconsole
MAILINGKIT_FROM_EMAILDefault sender address
MAILINGKIT_FROM_NAMEDefault sender display name
MAILINGKIT_TEMPLATES_DIRTemplate folder
MAILINGKIT_REDIRECT_TOSend every email to this address instead
MAILINGKIT_MAX_ATTEMPTSAttempts per send for transient failures3

SMTP

VariableMeaningDefault
MAILINGKIT_SMTP_HOSTServer host (required)
MAILINGKIT_SMTP_PORTServer port587, 465 or 25 by security
MAILINGKIT_SMTP_SECURITYstarttls, ssl or nonestarttls
MAILINGKIT_SMTP_USERNAMELogin (set with the password)
MAILINGKIT_SMTP_PASSWORDPassword, held as a Secret
MAILINGKIT_SMTP_TIMEOUTSeconds30

Resend

VariableMeaningDefault
MAILINGKIT_RESEND_API_KEYAPI key (required)
MAILINGKIT_RESEND_BASE_URLAPI base URLhttps://api.resend.com
MAILINGKIT_RESEND_TIMEOUTSeconds30

Development providers

VariableMeaningDefault
MAILINGKIT_FILE_DIROutput folder for the file provider.mailingkit/outbox
MAILINGKIT_CONSOLE_SHOW_HTMLAlso print the HTML bodyfalse

Constructor options

python
MailingKit(
    provider=None,                 # an EmailProvider; console when omitted
    default_sender=None,           # "App <no-reply@example.com>" or an Address
    templates=None,                # a folder path or a TemplateRenderer
    retry=None,                    # RetryPolicy(); NO_RETRY to disable
    idempotency_store=None,        # InMemoryIdempotencyStore() by default
    idempotency_ttl=86400,         # seconds a key is remembered
    redirect_to=None,              # one inbox for every email (staging)
    limits=None,                   # Limits(max_recipients=50, max_message_bytes=10 MiB)
    hooks=(),                      # callables receiving MailEvent
)

Configuration problems raise ConfigurationError with the exact variable name, at startup rather than on the first send.