complete_mail(message,
sender,
recipients,
subject,
default_charset,
cc=[ ] ,
bcc=[ ] ,
message_id_string=None,
date=None,
headers=[ ] )
| source code
|
Fill in the From, To, Cc, Subject, Date and Message-Id headers
of one existing message regarding the parameters.
- Parameters:
message (email.Message) - the message to fill in
sender (tuple) - a tuple of the form (u'Sender Name', 'sender.address@domain.com')
recipients (list) - a list of addresses. Address can be tuple or string like expected
by format_addresses(), for example: [
'address@dmain.com', (u'Recipient Name',
'recipient.address@domain.com'), ... ]
subject (str) - The subject of the message, can be a unicode string or a string
encoded using default_charset encoding. Prefert unicode to
byte string here.
default_charset (str) - The default charset for this email. Arguments that are non
unicode string are supposed to be encoded using this charset.
This charset will be used has an hint when encoding mail
content.
cc (list) - The carbone copy addresses. Same format as the
recipients argument.
bcc (list) - The blind carbone copy addresses. Same format as the
recipients argument.
message_id_string (str or None) - if None, don't append any Message-ID to the mail, let the
SMTP do the job, else use the string to generate a unique
ID using email.utils.make_msgid() . The
generated value is returned as last argument. For example use the
name of your application.
date (int or None) - utc time in second from the epoch or None. If None then use
curent time time.time() instead.
headers (list of tuple) - a list of (field, value) tuples to fill in the mail
header fields. Values are encoded using default_charset.
- Returns: tuple
- (payload, mail_from, rcpt_to, msg_id)
-
payload (str) is the content of the email, generated
from the message
-
mail_from (str) is the address of the sender to pass
to the SMTP host
-
rcpt_to (list) is a list of the recipients addresses
to pass to the SMTP host of the form
[ 'a@b.com',
c@d.com', ] . This combine all recipients, carbone
copy addresses and blind carbone copy addresses.
-
msg_id (None or str) None if message_id_string==None
else the generated value for the message-id. If not None,
this Message-ID is already written into the payload.
>>> import email.mime.text
>>> msg=email.mime.text.MIMEText('The text.', 'plain', 'us-ascii')
>>>
>>> payload, mail_from, rcpt_to, msg_id=complete_mail(msg, ('Me', 'me@foo.com'),
... [ ('Him', 'him@bar.com'), ], 'Non unicode subject', 'iso-8859-1',
... cc=['her@bar.com',], date=1313558269, headers=[('User-Agent', u'pyzmail'), ])
>>> print payload
...
...
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
From: Me <me@foo.com>
To: Him <him@bar.com>
Cc: her@bar.com
Subject: =?iso-8859-1?q?Non_unicode_subject?=
Date: ...
User-Agent: ...pyzmail...
<BLANKLINE>
The text.
>>> print 'mail_from=%r rcpt_to=%r' % (mail_from, rcpt_to)
mail_from='me@foo.com' rcpt_to=['him@bar.com', 'her@bar.com']
|