b.e.EmailMessage(object) : class documentation

Part of bzrlib.email_message View In Hierarchy

An email message.

The constructor needs an origin address, a destination address or addresses and a subject, and accepts a body as well. Add additional parts to the message with add_inline_attachment(). Retrieve the entire formatted message with as_string().

Headers can be accessed with get() and msg[], and modified with msg[] =.

Method __init__ Create an email message.
Method add_inline_attachment Add an inline attachment to the message.
Method as_string Return the entire formatted message as a string.
Method get Get a header from the message, returning failobj if not present.
Method __getitem__ Get a header from the message, returning None if not present.
Method __setitem__ Undocumented
Static Method send Create an email message and send it with SMTPConnection.
Static Method address_to_encoded_header RFC2047-encode an address if necessary.
Static Method string_with_encoding Return a str object together with an encoding.
def __init__(self, from_address, to_address, subject, body=None):
Create an email message.

All four parameters can be unicode strings or byte strings, but for the addresses and subject byte strings must be encoded in UTF-8. For the body any byte string will be accepted; if it's not ASCII or UTF-8, it'll be sent with charset=8-bit.

Parametersfrom_addressThe origin address, to be put on the From header.
to_addressThe destination address of the message, to be put in the To header. Can also be a list of addresses.
subjectThe subject of the message.
bodyIf given, the body of the message.
def add_inline_attachment(self, body, filename=None, mime_subtype='plain'):
Add an inline attachment to the message.

The attachment body will be displayed inline, so do not use this function to attach binary attachments.

ParametersbodyA text to attach. Can be an unicode string or a byte string, and it'll be sent as ascii, utf-8, or 8-bit, in that preferred order.
filenameThe name for the attachment. This will give a default name for email programs to save the attachment.
mime_subtypeMIME subtype of the attachment (eg. 'plain' for text/plain [default]).
def as_string(self, boundary=None):
Return the entire formatted message as a string.
ParametersboundaryThe boundary to use between MIME parts, if applicable. Used for tests.
def get(self, header, failobj=None):
Get a header from the message, returning failobj if not present.
def __getitem__(self, header):
Get a header from the message, returning None if not present.

This method intentionally does not raise KeyError to mimic the behavior of __getitem__ in email.Message.

def __setitem__(self, header, value):
Undocumented
@staticmethod
def send(config, from_address, to_address, subject, body, attachment=None, attachment_filename=None, attachment_mime_subtype='plain'):
Create an email message and send it with SMTPConnection.

See EmailMessage.__init__() and EmailMessage.add_inline_attachment() for an explanation of the rest of parameters.

Parametersconfigconfig object to pass to SMTPConnection constructor.
@staticmethod
def address_to_encoded_header(address):
RFC2047-encode an address if necessary.
ParametersaddressAn unicode string, or UTF-8 byte string.
ReturnsA possibly RFC2047-encoded string.
@staticmethod
def string_with_encoding(string_):
Return a str object together with an encoding.
Parametersstring_A str or unicode object.
ReturnsA tuple (str, encoding), where encoding is one of 'ascii', 'utf-8', or '8-bit', in that preferred order.
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.