Mail Bundle API

flask_unchained.bundles.mail

MailBundle

The Mail Bundle.

flask_unchained.bundles.mail.config

Config

Default configuration options for the mail bundle.

DevConfig

Development-specific config options for the mail bundle.

ProdConfig

Production-specific config options for the mail bundle.

StagingConfig

Inherit settings from production.

TestConfig

Test-specific config options for the mail bundle.

flask_unchained.bundles.mail.extensions

Mail

The Mail extension.

MailBundle

class flask_unchained.bundles.mail.MailBundle[source]

The Mail Bundle.

name: str = 'mail_bundle'

The name of the Mail Bundle.

command_group_names = ['mail']

Click groups for the Mail Bundle.

Config

class flask_unchained.bundles.mail.config.Config[source]

Default configuration options for the mail bundle.

MAIL_SERVER = '127.0.0.1'

The hostname/IP of the mail server.

MAIL_PORT = 25

The port the mail server is running on.

MAIL_USERNAME = None

The username to connect to the mail server with, if any.

MAIL_PASSWORD = None

The password to connect to the mail server with, if any.

MAIL_USE_TLS = False

Whether or not to use TLS.

MAIL_USE_SSL = False

Whether or not to use SSL.

MAIL_DEFAULT_SENDER = 'Flask Mail <noreply@localhost>'

The default sender to use, if none is specified otherwise.

MAIL_SEND_FN(to: Union[str, List[str], None] = None, template: Optional[str] = None, **kwargs)

The function to use for sending emails. Defaults to _send_mail(). Any customized send function must implement the same function signature:

def send_mail(subject_or_message: Optional[Union[str, Message]] = None,
              to: Optional[Union[str, List[str]] = None,
              template: Optional[str] = None,
              **kwargs):
    # ...

NOTE: subject_or_message is optional because you can also pass subject as a keyword argument, and to is optional because you can also pass recipients as a keyword argument. These are artifacts of backwards-compatibility with vanilla Flask-Mail.

MAIL_DEBUG = 0

The debug level to set for interactions with the mail server.

MAIL_MAX_EMAILS = None

The maximum number of emails to send per connection with the mail server.

MAIL_SUPPRESS_SEND = False

Whether or not to actually send emails, or just pretend to. This is mainly useful for testing.

MAIL_ASCII_ATTACHMENTS = False

Whether or not to coerce attachment filenames to ASCII.

class flask_unchained.bundles.mail.config.DevConfig[source]

Development-specific config options for the mail bundle.

MAIL_DEBUG = 1

Set the mail server debug level to 1 in development.

MAIL_PORT = 1025

In development, the mail bundle is configured to connect to MailHog.

class flask_unchained.bundles.mail.config.ProdConfig[source]

Production-specific config options for the mail bundle.

MAIL_PORT = 465

In production, the mail bundle is configured to connect using SSL.

MAIL_USE_SSL = True

Set use SSL to True in production.

class flask_unchained.bundles.mail.config.StagingConfig[source]

Inherit settings from production.

class flask_unchained.bundles.mail.config.TestConfig[source]

Test-specific config options for the mail bundle.

MAIL_SUPPRESS_SEND = True

Do not actually send emails when running tests.

The Mail Extension

class flask_unchained.bundles.mail.Mail[source]

The Mail extension:

from flask_unchained.bundles.mail import mail
send_message(subject_or_message: Union[flask_mail.Message, str, None] = None, to: Union[str, List[str], None] = None, **kwargs)[source]

Send an email using the send function as configured by MAIL_SEND_FN.

Parameters
  • subject_or_message – The subject line, or an instance of flask_mail.Message.

  • to – The message recipient(s).

  • kwargs – Extra values to pass on to Message