Class Message
source code
object --+
|
Message
- Known Subclasses:
-
Simple e-mail message class.
Message provides a means to easily create e-mail messages to be sent
through the Dispatch mechanism or MailPool. Message provides various
helper functions to correctly format plain text, dual plain text and rich
text MIME encoded messages, as well as handle embedded and external
attachments.
All properties can be set from the constructor.
Example usage:
import turbomail
message = turbomail.Message(
"from@host.com",
"to@host.com",
"Subject",
plain="This is a plain message."
)
E-mail addresses can be represented as any of the following:
-
A string.
-
A 2-tuple of ("Full Name", "name@host.tld")
Encoding can be overridden on a per-message basis, but note that
'utf-8-qp' modifies the default 'utf-8' behaviour to output
quoted-printable, and you will have to change it back yourself if you
want base64 encoding.
|
__init__(self,
sender=None,
recipient=None,
subject=None,
**kw)
Instantiate a new Message object. |
source code
|
|
|
|
|
embed(self,
file,
name)
Attach an on-disk image file and prepare for HTML embedding. |
source code
|
|
|
_normalize(self,
addresslist)
A utility function to return a list of addresses as a string. |
source code
|
|
|
|
|
|
tuple
|
__call__(self)
Produce a valid MIME-encoded message and return valid input for the
Dispatch class to process. |
source code
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
bool
|
_dirty
Has there been changes since the MIME message was last generated?
|
bool
|
_processed
Has the MIME-encoded message been generated?
|
list
|
attachments
A list of MIME-encoded attachments.
|
|
bcc
The BCC header.
|
|
cc
The CC header.
|
string
|
date
The Date header.
|
|
disposition
The Disposition-Notification-To header.
|
list
|
embedded
A list of MIME-encoded embedded obejects for use in the text/html
part.
|
string
|
encoding
Content encoding.
|
|
headers
A list of additional headers.
|
string
|
organization
The Organization header.
|
string
|
plain
The plain text content of the message.
|
int
|
priority
The X-Priority header, a number ranging from 1-5.
|
|
recipient
The To header.
|
|
replyto
The X-Reply-To header.
|
string
|
rich
The rich text (HTML) content of the message.
|
|
sender
The From header.
|
|
smtpfrom
The envelope address, if different than the sender.
|
string
|
subject
The Subject header.
|
Inherited from object :
__class__
|
__init__(self,
sender=None,
recipient=None,
subject=None,
**kw)
(Constructor)
| source code
|
Instantiate a new Message object.
No arguments are required, as everything can be set using class
properties. Alternatively, everything can be set using the
constructor, using named arguments. The first three positional arguments
can be used to quickly prepare a simple message.
An instance of Message is callable.
- Parameters:
sender (string) - The e-mail address of the sender. This is encoded as the
"From:" SMTP header.
recipient (string) - The recipient of the message. This gets encoded as the
"To:" SMTP header.
subject (string) - The subject of the message. This gets encoded as the
"Subject:" SMTP header.
- Overrides:
object.__init__
|
Attach an on-disk file to this message.
- Parameters:
file - The path to the file you wish to attach, or an instance of a
file-like object.
name (string) - You can optionally override the filename of the attached file.
This name will appear in the recipient's mail viewer.
Optional if passing an on-disk path. Required if passing a
file-like object.
|
Attach an on-disk image file and prepare for HTML embedding.
This method should only be used to embed images.
- Parameters:
file - The path to the file you wish to attach, or an instance of a
file-like object.
name (string) - You can optionally override the filename of the attached file.
This name will appear in the recipient's mail viewer.
Optional if passing an on-disk path. Required if passing a
file-like object.
|
Produce the final MIME message.
Additionally, if only a rich text part exits, strip the HTML to
produce the plain text part. (This produces identical output as KID,
although lacks reverse entity conversion -- &, etc.)
|
Set the dirty flag as properties are updated.
- Overrides:
object.__setattr__
|
Produce a valid MIME-encoded message and return valid input for the
Dispatch class to process.
- Returns: tuple
- Returns a tuple containing sender and recipient e-mail addresses
and the string output of MIMEMultipart.
|
bcc
The BCC header. As per the recipient property. Optional.
|
cc
The CC header. As per the recipient property. Optional.
|
date
The Date header. Must be correctly formatted.
- Type:
- string
|
disposition
The Disposition-Notification-To header. A string or 2-tuple.
Optional.
|
encoding
Content encoding. Pulled from mail.encoding, defaults to
'us-ascii'.
- Type:
- string
|
headers
A list of additional headers. Can be added in a wide variety of formats:
a list of strings, list of tuples, a dictionary, etc. Look at the code.
|
organization
The Organization header. Optional.
- Type:
- string
|
priority
The X-Priority header, a number ranging from 1-5. Optional.
Default: 3
- Type:
- int
|
recipient
The To header. A string, 2-tuple, or list of strings or 2-tuples.
|
replyto
The X-Reply-To header. A string or 2-tuple. Optional.
|
rich
The rich text (HTML) content of the message. Plain text content
must be available as well.
- Type:
- string
|
sender
The From header. A string or 2-tuple.
|