API

class flask_mail.Mail(app=None)

Manages email messaging

Parameters: app – Flask instance

connect()

Opens a connection to the mail host.

send(message)

Sends a single message instance. If TESTING is True the message will not actually be sent.

Parameters: message – a Message instance.

send_message(*args, **kwargs)

Shortcut for send(msg).

Takes same arguments as Message constructor.

Versionadded: 0.3.5

class flask_mail.Attachment(filename=None, content_type=None, data=None, disposition=None, headers=None)

Encapsulates file attachment information.

Versionadded:

0.3.5

Parameters:

  • filename – filename of attachment
  • content_type – file mimetype
  • data – the raw file data
  • disposition – content-disposition (if any)

class flask_mail.Connection(mail)

Handles connection to host.

send(message, envelope_from=None)

Verifies and sends message.

Parameters:

  • message – Message instance.
  • envelope_from – Email address to be used in MAIL FROM command.

send_message(*args, **kwargs)

Shortcut for send(msg).

Takes same arguments as Message constructor.

Versionadded: 0.3.5

class flask_mail.Message(subject='', recipients=None, body=None, html=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 – email subject header
  • recipients – list of email addresses
  • body – plain text message
  • html – HTML message
  • sender – email sender address, or MAIL_DEFAULT_SENDER by default
  • cc – CC list
  • bcc – BCC list
  • attachments – list of Attachment instances
  • reply_to – reply-to address
  • date – send date
  • charset – message character set
  • extra_headers – A dictionary of additional headers for the message
  • mail_options – A list of ESMTP options to be used in MAIL FROM command
  • rcpt_options – A list of ESMTP options to be used in RCPT commands

add_recipient(recipient)

Adds another recipient to the message.

Parameters: recipient – email address of recipient.

attach(filename=None, content_type=None, data=None, disposition=None, headers=None)

Adds an attachment to the message.

Parameters:

  • filename – filename of attachment
  • content_type – file mimetype
  • data – the raw file data
  • disposition – content-disposition (if any)