API¶
Anything documented here is part of the public API that Flask-Mail provides, unless otherwise indicated. Anything not documented here is considered internal or private and may change at any time.
- class flask_mail.Mail(app=None)¶
Manages email messaging.
- Parameters:
app (Flask | None)
- init_app(app)¶
Initializes your mail settings from the application settings.
You can use this if you want to set up your Mail instance at configuration time.
- Parameters:
app (Flask)
- Return type:
_Mail
- send(message)¶
Sends a single message instance. If TESTING is True the message will not actually be sent.
- Parameters:
message (Message) – a Message instance.
- Return type:
None
- connect()¶
Opens a connection to the mail host.
- Return type:
- class flask_mail.Attachment(filename=None, content_type=None, data=None, disposition=None, headers=None)¶
Encapsulates file attachment information.
- Parameters:
Changed in version 0.10.0: The
dataargument is required.
- class flask_mail.Connection(mail)¶
Handles connection to host.
- Parameters:
mail (Mail)
- send(message, envelope_from=None)¶
Verifies and sends message.
- class flask_mail.Message(subject='', recipients=None, body=None, html=None, alts=None, sender=None, cc=None, bcc=None, attachments=None, reply_to=None, date=None, charset=None, extra_headers=None, mail_options=None, rcpt_options=None)¶
Encapsulates an email message.
- Parameters:
subject (str) – email subject header
recipients (list[str | tuple[str, str]] | None) – list of email addresses
body (str | None) – plain text message
html (str | None) – HTML message
alts (dict[str, str] | c.Iterable[tuple[str, str]] | None) – A dict or an iterable to go through dict() that contains multipart alternatives
sender (str | tuple[str, str] | None) – email sender address, or MAIL_DEFAULT_SENDER by default
attachments (list[Attachment] | None) – list of Attachment instances
date (float | None) – send date
charset (str | None) – message character set
extra_headers (dict[str, str] | None) – A dictionary of additional headers for the message
mail_options (list[str] | None) – A list of ESMTP options to be used in MAIL FROM command
rcpt_options (list[str] | None) – A list of ESMTP options to be used in RCPT commands
- add_recipient(recipient)¶
Adds another recipient to the message.
- attach(filename=None, content_type=None, data=None, disposition=None, headers=None)¶
Adds an attachment to the message.
- flask_mail.email_dispatched¶
Signal sent when an email is dispatched. This signal will also be sent in testing mode, even though the email will not actually be sent.