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

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

Issue 10321: Add support for Message objects and binary data to smtplib.sendmail
Patch Set: Created 8 years, 11 months 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 | « no previous file | Lib/smtplib.py » ('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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 The server does not support the STARTTLS extension. 257 The server does not support the STARTTLS extension.
258 258
259 :exc:`RuntimeError` 259 :exc:`RuntimeError`
260 SSL/TLS support is not available to your Python interpreter. 260 SSL/TLS support is not available to your Python interpreter.
261 261
262 262
263 .. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_option s=[]) 263 .. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_option s=[])
264 264
265 Send mail. The required arguments are an :rfc:`822` from-address string, a l ist 265 Send mail. The required arguments are an :rfc:`822` from-address string, a l ist
266 of :rfc:`822` to-address strings (a bare string will be treated as a list wit h 1 266 of :rfc:`822` to-address strings (a bare string will be treated as a list wit h 1
267 address), and a message string. The caller may pass a list of ESMTP options 267 address), and a message. 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. The :class:`SMTP` does not modify t he
278 message headers in any way. 278 message headers in any way, with the sole exception of the :mailheader:`Bc c`
279 field if *msg* is a :class:`~email.message.Message` object.
280
281 msg may be a string containing characters in the ASCII range, or a byte
282 string, or a :class:`~email.message.Message` object. A string is encoded to
283 bytes using the ascii codec, and lone ``\r`` and ``\n`` characters are
284 converted to ``\r\n`` characters. A byte string is transmitted as is. A
285 Message object is serialized using :class:`~email.generator.BytesGenerator`.
286
287 When msg is a Message object, *from_addr* and *to_addrs* may be set to
288 ``None``, in which case the *from_addr* is taken from the :mailheader:`From`
289 header of the Message, and *to_addrs* is composed from the addresses listed
290 in the :mailheader:`To`, :mailheader:`CC`, and :mailheader:`Bcc` fields.
291 Regardless, any Bcc field in the ``Message`` object is deleted before it is
292 serialized.
293
294 .. note::
295
296 The :mailheader:`Bcc` header is removed *only* when *msg* is a
297 :class:`~email.message.Message` object.
298
299 If there has been no previous EHLO or HELO command this session, this method
300 tries ESMTP EHLO first. If the server does ESMTP, message size and each of
301 the specified options will be passed to it. If EHLO fails, HELO will be
302 tried and ESMTP options suppressed.
279 303
280 If there has been no previous ``EHLO`` or ``HELO`` command this session, this 304 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 305 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 306 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 307 feature set the server advertises). If ``EHLO`` fails, ``HELO`` will be trie d
284 and ESMTP options suppressed. 308 and ESMTP options suppressed.
285 309
286 This method will return normally if the mail is accepted for at least one 310 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 311 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 312 not raise an exception, then someone should get your mail. If this method doe s
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 print("Message length is", len(msg)) 383 print("Message length is", len(msg))
360 384
361 server = smtplib.SMTP('localhost') 385 server = smtplib.SMTP('localhost')
362 server.set_debuglevel(1) 386 server.set_debuglevel(1)
363 server.sendmail(fromaddr, toaddrs, msg) 387 server.sendmail(fromaddr, toaddrs, msg)
364 server.quit() 388 server.quit()
365 389
366 .. note:: 390 .. note::
367 391
368 In general, you will want to use the :mod:`email` package's features to 392 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 393 construct an email message, which you can then send
370 via :meth:`sendmail`; see :ref:`email-examples`. 394 via :meth:`~smtplib.SMTP.sendmail`; see :ref:`email-examples`.
OLDNEW
« no previous file with comments | « no previous file | Lib/smtplib.py » ('j') | no next file with comments »

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