Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(167007)

Side by Side Diff: Doc/library/smtplib.rst

Issue 10321: Add support for Message objects and binary data to smtplib.sendmail
Patch Set: Created 9 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/includes/email-simple.py ('k') | Doc/whatsnew/3.2.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`smtplib` --- SMTP protocol client 1 :mod:`smtplib` --- SMTP protocol client
2 ======================================= 2 =======================================
3 3
4 .. module:: smtplib 4 .. module:: smtplib
5 :synopsis: SMTP protocol client (requires sockets). 5 :synopsis: SMTP protocol client (requires sockets).
6 .. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com> 6 .. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com>
7 7
8 8
9 .. index:: 9 .. index::
10 pair: SMTP; protocol 10 pair: SMTP; protocol
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 address), and a message string. The caller may pass a list of ESMTP options 267 address), and a message string. The caller may pass a list of ESMTP options
268 (such as ``8bitmime``) to be used in ``MAIL FROM`` commands as *mail_options* . 268 (such as ``8bitmime``) to be used in ``MAIL FROM`` commands as *mail_options* .
269 ESMTP options (such as ``DSN`` commands) that should be used with all ``RCPT` ` 269 ESMTP options (such as ``DSN`` commands) that should be used with all ``RCPT` `
270 commands can be passed as *rcpt_options*. (If you need to use different ESMT P 270 commands can be passed as *rcpt_options*. (If you need to use different ESMT P
271 options to different recipients you have to use the low-level methods such as 271 options to different recipients you have to use the low-level methods such as
272 :meth:`mail`, :meth:`rcpt` and :meth:`data` to send the message.) 272 :meth:`mail`, :meth:`rcpt` and :meth:`data` to send the message.)
273 273
274 .. note:: 274 .. note::
275 275
276 The *from_addr* and *to_addrs* parameters are used to construct the messag e 276 The *from_addr* and *to_addrs* parameters are used to construct the messag e
277 envelope used by the transport agents. The :class:`SMTP` does not modify t he 277 envelope used by the transport agents. ``sendmail`` does not modify the
278 message headers in any way. 278 message headers in any way.
279
280 msg may be a string containing characters in the ASCII range, or a byte
281 string. A string is encoded to bytes using the ascii codec, and lone ``\r``
282 and ``\n`` characters are converted to ``\r\n`` characters. A byte string
283 is not modified.
279 284
280 If there has been no previous ``EHLO`` or ``HELO`` command this session, this 285 If there has been no previous ``EHLO`` or ``HELO`` command this session, this
281 method tries ESMTP ``EHLO`` first. If the server does ESMTP, message size and 286 method tries ESMTP ``EHLO`` first. If the server does ESMTP, message size and
282 each of the specified options will be passed to it (if the option is in the 287 each of the specified options will be passed to it (if the option is in the
283 feature set the server advertises). If ``EHLO`` fails, ``HELO`` will be trie d 288 feature set the server advertises). If ``EHLO`` fails, ``HELO`` will be trie d
284 and ESMTP options suppressed. 289 and ESMTP options suppressed.
285 290
286 This method will return normally if the mail is accepted for at least one 291 This method will return normally if the mail is accepted for at least one
287 recipient. Otherwise it will raise an exception. That is, if this method doe s 292 recipient. Otherwise it will raise an exception. That is, if this method doe s
288 not raise an exception, then someone should get your mail. If this method doe s 293 not raise an exception, then someone should get your mail. If this method doe s
(...skipping 14 matching lines...) Expand all
303 308
304 :exc:`SMTPSenderRefused` 309 :exc:`SMTPSenderRefused`
305 The server didn't accept the *from_addr*. 310 The server didn't accept the *from_addr*.
306 311
307 :exc:`SMTPDataError` 312 :exc:`SMTPDataError`
308 The server replied with an unexpected error code (other than a refusal of a 313 The server replied with an unexpected error code (other than a refusal of a
309 recipient). 314 recipient).
310 315
311 Unless otherwise noted, the connection will be open even after an exception i s 316 Unless otherwise noted, the connection will be open even after an exception i s
312 raised. 317 raised.
318
319 .. versionchanged:: 3.2 *msg* may be a byte string.
320
321
322 .. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, mail_options=[ ], rcpt_options=[])
323
324 This is a convenience method for calling :meth:`sendmail` with the message
325 represented by an :class:`email.message.Message` object. The arguments have
326 the same meaning as for :meth:`sendmail`, except that *msg* is a ``Message``
327 object.
328
329 If *from_addr* is ``None``, ``send_message`` sets its value to the value of
330 the :mailheader:`From` header from *msg*. If *to_addrs* is ``None``,
331 ``send_message`` combines the values (if any) of the :mailheader:`To`,
332 :mailheader:`CC`, and :mailheader:`Bcc` fields from *msg*. Regardless of
333 the values of *from_addr* and *to_addrs*, ``send_message`` deletes any Bcc
334 field from *msg*. It then serializes *msg* using
335 :class:`~email.generator.BytesGenerator` with ``\r\n`` as the *linesep*, and
336 calls :meth:`sendmail` to transmit the resulting message.
337
338 .. versionadded:: 3.2
313 339
314 340
315 .. method:: SMTP.quit() 341 .. method:: SMTP.quit()
316 342
317 Terminate the SMTP session and close the connection. Return the result of 343 Terminate the SMTP session and close the connection. Return the result of
318 the SMTP ``QUIT`` command. 344 the SMTP ``QUIT`` command.
319 345
320 346
321 Low-level methods corresponding to the standard SMTP/ESMTP commands ``HELP``, 347 Low-level methods corresponding to the standard SMTP/ESMTP commands ``HELP``,
322 ``RSET``, ``NOOP``, ``MAIL``, ``RCPT``, and ``DATA`` are also supported. 348 ``RSET``, ``NOOP``, ``MAIL``, ``RCPT``, and ``DATA`` are also supported.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 print("Message length is", len(msg)) 385 print("Message length is", len(msg))
360 386
361 server = smtplib.SMTP('localhost') 387 server = smtplib.SMTP('localhost')
362 server.set_debuglevel(1) 388 server.set_debuglevel(1)
363 server.sendmail(fromaddr, toaddrs, msg) 389 server.sendmail(fromaddr, toaddrs, msg)
364 server.quit() 390 server.quit()
365 391
366 .. note:: 392 .. note::
367 393
368 In general, you will want to use the :mod:`email` package's features to 394 In general, you will want to use the :mod:`email` package's features to
369 construct an email message, which you can then convert to a string and send 395 construct an email message, which you can then send
370 via :meth:`sendmail`; see :ref:`email-examples`. 396 via :meth:`~smtplib.SMTP.send_message`; see :ref:`email-examples`.
OLDNEW
« no previous file with comments | « Doc/includes/email-simple.py ('k') | Doc/whatsnew/3.2.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+