Envelope class

class envelopes.envelope.Envelope(to_addr=None, from_addr=None, subject=None, html_body=None, text_body=None, cc_addr=None, bcc_addr=None, headers=None, charset='utf-8')

The Envelope class.

Address formats

The following formats are supported for e-mail addresses:

  • "user@server.com" - just the e-mail address part as a string,
  • "Some User <user@server.com>" - name and e-mail address parts as a string,
  • ("user@server.com", "Some User") - e-mail address and name parts as a tuple.

Whenever you come to manipulate addresses feel free to use any (or all) of the formats above.

Parameters:
  • to_addrTo address or list of To addresses
  • from_addrFrom address
  • subject – message subject
  • html_body – optional HTML part of the message
  • text_body – optional plain text part of the message
  • cc_addr – optional single CC address or list of CC addresses
  • bcc_addr – optional single BCC address or list of BCC addresses
  • headers – optional dictionary of headers
  • charset – message charset
add_attachment(file_path, mimetype=None)

Attaches a file located at file_path to the envelope. If mimetype is not specified an attempt to guess it is made. If nothing is guessed then application/octet-stream is used.

add_bcc_addr(bcc_addr)

Adds a BCC address.

add_cc_addr(cc_addr)

Adds a CC address.

add_header(key, value)

Adds a custom header.

add_to_addr(to_addr)

Adds a To address.

bcc_addr

List of BCC addresses.

cc_addr

List of CC addresses.

charset

Message charset.

clear_bcc_addr()

Clears list of BCC addresses.

clear_cc_addr()

Clears list of CC addresses.

clear_headers()

Clears custom headers.

clear_to_addr()

Clears list of To addresses.

headers

Dictionary of custom headers.

send(*args, **kwargs)

Sends the envelope using a freshly created SMTP connection. args and kwargs are passed directly to envelopes.conn.SMTP constructor.

Returns a tuple of SMTP object and whatever its send method returns.

to_addr

List of To addresses.

to_mime_message()

Returns the envelope as email.mime.multipart.MIMEMultipart.

Previous topic

Envelopes in Flask example

Next topic

SMTP connection

This Page