diff options
author | R David Murray <rdmurray@bitdance.com> | 2011-07-03 01:03:19 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2011-07-03 01:03:19 (GMT) |
commit | ac4e5abc788dfd10474fe3b0a6c5c802d3159763 (patch) | |
tree | 9157a750e1c58b5fa72943c5a8def6bc61314b31 /Doc/library | |
parent | 623e8b86af8d8b34589478f7c85de49054e07a6d (diff) | |
download | cpython-ac4e5abc788dfd10474fe3b0a6c5c802d3159763.zip cpython-ac4e5abc788dfd10474fe3b0a6c5c802d3159763.tar.gz cpython-ac4e5abc788dfd10474fe3b0a6c5c802d3159763.tar.bz2 |
#12147: make send_message correctly handle Sender and Resent- headers.
Original patch by Nicolas Estibals. My tweaks to the patch were mostly
style/cosmetic, and adding more tests.
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/smtplib.rst | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 531a64d..5978a8f 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -323,21 +323,32 @@ An :class:`SMTP` instance has the following methods: .. versionchanged:: 3.2 *msg* may be a byte string. -.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, mail_options=[], rcpt_options=[]) +.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, \ + mail_options=[], rcpt_options=[]) This is a convenience method for calling :meth:`sendmail` with the message represented by an :class:`email.message.Message` object. The arguments have the same meaning as for :meth:`sendmail`, except that *msg* is a ``Message`` object. - If *from_addr* is ``None``, ``send_message`` sets its value to the value of - the :mailheader:`From` header from *msg*. If *to_addrs* is ``None``, - ``send_message`` combines the values (if any) of the :mailheader:`To`, - :mailheader:`CC`, and :mailheader:`Bcc` fields from *msg*. Regardless of - the values of *from_addr* and *to_addrs*, ``send_message`` deletes any Bcc - field from *msg*. It then serializes *msg* using + If *from_addr* is ``None`` or *to_addrs* is ``None``, ``send_message`` fills + those arguments with addresses extracted from the headers of *msg* as + specified in :rfc:`2822`\: *from_addr* is set to the :mailheader:`Sender` + field if it is present, and otherwise to the :mailheader:`From` field. + *to_adresses* combines the values (if any) of the :mailheader:`To`, + :mailheader:`Cc`, and :mailheader:`Bcc` fields from *msg*. If exactly one + set of :mailheader:`Resent-*` headers appear in the message, the regular + headers are ignored and the :mailheader:`Resent-*` headers are used instead. + If the message contains more than one set of :mailheader:`Resent-*` headers, + a :exc:`ValueError` is raised, since there is no way to unambiguously detect + the most recent set of :mailheader:`Resent-` headers. + + ``send_message`` serializes *msg* using :class:`~email.generator.BytesGenerator` with ``\r\n`` as the *linesep*, and - calls :meth:`sendmail` to transmit the resulting message. + calls :meth:`sendmail` to transmit the resulting message. Regardless of the + values of *from_addr* and *to_addrs*, ``send_message`` does not transmit any + :mailheader:`Bcc` or :mailheader:`Resent-Bcc` headers that may appear + in *msg*. .. versionadded:: 3.2 |