blob: b87ad5f326686e472cbfe5d76315572156da9c8d [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`smtplib` --- SMTP protocol client
2=======================================
3
4.. module:: smtplib
5 :synopsis: SMTP protocol client (requires sockets).
6.. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com>
7
8
9.. index::
10 pair: SMTP; protocol
11 single: Simple Mail Transfer Protocol
12
Raymond Hettinger469271d2011-01-27 20:38:46 +000013**Source code:** :source:`Lib/smtplib.py`
14
15--------------
16
Georg Brandl116aa622007-08-15 14:28:22 +000017The :mod:`smtplib` module defines an SMTP client session object that can be used
18to send mail to any Internet machine with an SMTP or ESMTP listener daemon. For
19details of SMTP and ESMTP operation, consult :rfc:`821` (Simple Mail Transfer
20Protocol) and :rfc:`1869` (SMTP Service Extensions).
21
22
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080023.. class:: SMTP(host='', port=0, local_hostname=None[, timeout], source_address=None)
Georg Brandl116aa622007-08-15 14:28:22 +000024
Martin Panter7462b6492015-11-02 03:37:02 +000025 An :class:`SMTP` instance encapsulates an SMTP connection. It has methods
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +000026 that support a full repertoire of SMTP and ESMTP operations. If the optional
R David Murray021362d2013-06-23 16:05:44 -040027 host and port parameters are given, the SMTP :meth:`connect` method is
28 called with those parameters during initialization. If specified,
29 *local_hostname* is used as the FQDN of the local host in the HELO/EHLO
30 command. Otherwise, the local hostname is found using
31 :func:`socket.getfqdn`. If the :meth:`connect` call returns anything other
32 than a success code, an :exc:`SMTPConnectError` is raised. The optional
33 *timeout* parameter specifies a timeout in seconds for blocking operations
34 like the connection attempt (if not specified, the global default timeout
R David Murray6ceca4e2014-06-09 16:41:06 -040035 setting will be used). If the timeout expires, :exc:`socket.timeout` is
36 raised. The optional source_address parameter allows to bind
R David Murray021362d2013-06-23 16:05:44 -040037 to some specific source address in a machine with multiple network
38 interfaces, and/or to some specific source TCP port. It takes a 2-tuple
39 (host, port), for the socket to bind to as its source address before
40 connecting. If omitted (or if host or port are ``''`` and/or 0 respectively)
41 the OS default behavior will be used.
Georg Brandl116aa622007-08-15 14:28:22 +000042
43 For normal use, you should only require the initialization/connect,
Jesus Ceac73f8632012-12-26 16:47:03 +010044 :meth:`sendmail`, and :meth:`~smtplib.quit` methods.
45 An example is included below.
Georg Brandl116aa622007-08-15 14:28:22 +000046
Barry Warsaw1f5c9582011-03-15 15:04:44 -040047 The :class:`SMTP` class supports the :keyword:`with` statement. When used
48 like this, the SMTP ``QUIT`` command is issued automatically when the
49 :keyword:`with` statement exits. E.g.::
50
51 >>> from smtplib import SMTP
52 >>> with SMTP("domain.org") as smtp:
53 ... smtp.noop()
54 ...
55 (250, b'Ok')
56 >>>
57
Antoine Pitrou45456a02011-04-26 18:53:42 +020058 .. versionchanged:: 3.3
Barry Warsaw1f5c9582011-03-15 15:04:44 -040059 Support for the :keyword:`with` statement was added.
60
Senthil Kumaranb351a482011-07-31 09:14:17 +080061 .. versionchanged:: 3.3
62 source_address argument was added.
Georg Brandl116aa622007-08-15 14:28:22 +000063
R David Murray36beb662013-06-23 15:47:50 -040064.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, \
65 certfile=None [, timeout], context=None, \
66 source_address=None)
Georg Brandl116aa622007-08-15 14:28:22 +000067
Martin Panter7462b6492015-11-02 03:37:02 +000068 An :class:`SMTP_SSL` instance behaves exactly the same as instances of
Georg Brandl116aa622007-08-15 14:28:22 +000069 :class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +000070 required from the beginning of the connection and using :meth:`starttls` is
71 not appropriate. If *host* is not specified, the local host is used. If
R David Murray36beb662013-06-23 15:47:50 -040072 *port* is zero, the standard SMTP-over-SSL port (465) is used. The optional
Antoine Pitrouc5e075f2014-03-22 18:19:11 +010073 arguments *local_hostname*, *timeout* and *source_address* have the same
74 meaning as they do in the :class:`SMTP` class. *context*, also optional,
75 can contain a :class:`~ssl.SSLContext` and allows to configure various
76 aspects of the secure connection. Please read :ref:`ssl-security` for
77 best practices.
78
79 *keyfile* and *certfile* are a legacy alternative to *context*, and can
80 point to a PEM formatted private key and certificate chain file for the
81 SSL connection.
Georg Brandl116aa622007-08-15 14:28:22 +000082
Antoine Pitroue0650202011-05-18 18:03:09 +020083 .. versionchanged:: 3.3
84 *context* was added.
85
Senthil Kumaranb351a482011-07-31 09:14:17 +080086 .. versionchanged:: 3.3
87 source_address argument was added.
Georg Brandl116aa622007-08-15 14:28:22 +000088
Christian Heimesa5768f72013-12-02 20:44:17 +010089 .. versionchanged:: 3.4
90 The class now supports hostname check with
Antoine Pitrouc5e075f2014-03-22 18:19:11 +010091 :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
92 :data:`ssl.HAS_SNI`).
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080093
94.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None)
Georg Brandl116aa622007-08-15 14:28:22 +000095
96 The LMTP protocol, which is very similar to ESMTP, is heavily based on the
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080097 standard SMTP client. It's common to use Unix sockets for LMTP, so our
98 :meth:`connect` method must support that as well as a regular host:port
Senthil Kumaranb351a482011-07-31 09:14:17 +080099 server. The optional arguments local_hostname and source_address have the
R David Murray021362d2013-06-23 16:05:44 -0400100 same meaning as they do in the :class:`SMTP` class. To specify a Unix
101 socket, you must use an absolute path for *host*, starting with a '/'.
Georg Brandl116aa622007-08-15 14:28:22 +0000102
R David Murray021362d2013-06-23 16:05:44 -0400103 Authentication is supported, using the regular SMTP mechanism. When using a
104 Unix socket, LMTP generally don't support or require any authentication, but
105 your mileage might vary.
Georg Brandl116aa622007-08-15 14:28:22 +0000106
Georg Brandl116aa622007-08-15 14:28:22 +0000107
108A nice selection of exceptions is defined as well:
109
110
111.. exception:: SMTPException
112
R David Murray8a345962013-04-14 06:46:35 -0400113 Subclass of :exc:`OSError` that is the base exception class for all
Ned Deily7cf5e612013-08-13 01:15:14 -0700114 the other exceptions provided by this module.
Georg Brandl116aa622007-08-15 14:28:22 +0000115
Larry Hastings3732ed22014-03-15 21:13:56 -0700116 .. versionchanged:: 3.4
117 SMTPException became subclass of :exc:`OSError`
118
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120.. exception:: SMTPServerDisconnected
121
122 This exception is raised when the server unexpectedly disconnects, or when an
123 attempt is made to use the :class:`SMTP` instance before connecting it to a
124 server.
125
126
127.. exception:: SMTPResponseException
128
129 Base class for all exceptions that include an SMTP error code. These exceptions
130 are generated in some instances when the SMTP server returns an error code. The
131 error code is stored in the :attr:`smtp_code` attribute of the error, and the
132 :attr:`smtp_error` attribute is set to the error message.
133
134
135.. exception:: SMTPSenderRefused
136
137 Sender address refused. In addition to the attributes set by on all
138 :exc:`SMTPResponseException` exceptions, this sets 'sender' to the string that
139 the SMTP server refused.
140
141
142.. exception:: SMTPRecipientsRefused
143
144 All recipient addresses refused. The errors for each recipient are accessible
145 through the attribute :attr:`recipients`, which is a dictionary of exactly the
146 same sort as :meth:`SMTP.sendmail` returns.
147
148
149.. exception:: SMTPDataError
150
151 The SMTP server refused to accept the message data.
152
153
154.. exception:: SMTPConnectError
155
156 Error occurred during establishment of a connection with the server.
157
158
159.. exception:: SMTPHeloError
160
161 The server refused our ``HELO`` message.
162
163
164.. exception:: SMTPAuthenticationError
165
166 SMTP authentication went wrong. Most probably the server didn't accept the
167 username/password combination provided.
168
169
170.. seealso::
171
172 :rfc:`821` - Simple Mail Transfer Protocol
173 Protocol definition for SMTP. This document covers the model, operating
174 procedure, and protocol details for SMTP.
175
176 :rfc:`1869` - SMTP Service Extensions
177 Definition of the ESMTP extensions for SMTP. This describes a framework for
178 extending SMTP with new commands, supporting dynamic discovery of the commands
179 provided by the server, and defines a few additional commands.
180
181
182.. _smtp-objects:
183
184SMTP Objects
185------------
186
187An :class:`SMTP` instance has the following methods:
188
189
190.. method:: SMTP.set_debuglevel(level)
191
192 Set the debug output level. A true value for *level* results in debug messages
193 for connection and for all messages sent to and received from the server.
194
195
Georg Brandl18244152009-09-02 20:34:52 +0000196.. method:: SMTP.docmd(cmd, args='')
Georg Brandl116aa622007-08-15 14:28:22 +0000197
Georg Brandl18244152009-09-02 20:34:52 +0000198 Send a command *cmd* to the server. The optional argument *args* is simply
Georg Brandl116aa622007-08-15 14:28:22 +0000199 concatenated to the command, separated by a space.
200
201 This returns a 2-tuple composed of a numeric response code and the actual
202 response line (multiline responses are joined into one long line.)
203
204 In normal operation it should not be necessary to call this method explicitly.
205 It is used to implement other methods and may be useful for testing private
206 extensions.
207
208 If the connection to the server is lost while waiting for the reply,
209 :exc:`SMTPServerDisconnected` will be raised.
210
211
R David Murray14ee3cf2013-04-13 14:40:33 -0400212.. method:: SMTP.connect(host='localhost', port=0)
213
214 Connect to a host on a given port. The defaults are to connect to the local
215 host at the standard SMTP port (25). If the hostname ends with a colon (``':'``)
216 followed by a number, that suffix will be stripped off and the number
217 interpreted as the port number to use. This method is automatically invoked by
218 the constructor if a host is specified during instantiation. Returns a
219 2-tuple of the response code and message sent by the server in its
220 connection response.
221
222
Georg Brandl18244152009-09-02 20:34:52 +0000223.. method:: SMTP.helo(name='')
Georg Brandl116aa622007-08-15 14:28:22 +0000224
225 Identify yourself to the SMTP server using ``HELO``. The hostname argument
226 defaults to the fully qualified domain name of the local host.
Benjamin Petersonae5360b2008-09-08 23:05:23 +0000227 The message returned by the server is stored as the :attr:`helo_resp` attribute
228 of the object.
Georg Brandl116aa622007-08-15 14:28:22 +0000229
230 In normal operation it should not be necessary to call this method explicitly.
231 It will be implicitly called by the :meth:`sendmail` when necessary.
232
233
Georg Brandl18244152009-09-02 20:34:52 +0000234.. method:: SMTP.ehlo(name='')
Georg Brandl116aa622007-08-15 14:28:22 +0000235
236 Identify yourself to an ESMTP server using ``EHLO``. The hostname argument
237 defaults to the fully qualified domain name of the local host. Examine the
Georg Brandl48310cd2009-01-03 21:18:54 +0000238 response for ESMTP option and store them for use by :meth:`has_extn`.
239 Also sets several informational attributes: the message returned by
240 the server is stored as the :attr:`ehlo_resp` attribute, :attr:`does_esmtp`
Benjamin Petersonae5360b2008-09-08 23:05:23 +0000241 is set to true or false depending on whether the server supports ESMTP, and
242 :attr:`esmtp_features` will be a dictionary containing the names of the
243 SMTP service extensions this server supports, and their
244 parameters (if any).
Georg Brandl116aa622007-08-15 14:28:22 +0000245
246 Unless you wish to use :meth:`has_extn` before sending mail, it should not be
247 necessary to call this method explicitly. It will be implicitly called by
248 :meth:`sendmail` when necessary.
249
Christian Heimes679db4a2008-01-18 09:56:22 +0000250.. method:: SMTP.ehlo_or_helo_if_needed()
251
252 This method call :meth:`ehlo` and or :meth:`helo` if there has been no
253 previous ``EHLO`` or ``HELO`` command this session. It tries ESMTP ``EHLO``
254 first.
255
Georg Brandl1f01deb2009-01-03 22:47:39 +0000256 :exc:`SMTPHeloError`
Christian Heimes679db4a2008-01-18 09:56:22 +0000257 The server didn't reply properly to the ``HELO`` greeting.
258
Georg Brandl116aa622007-08-15 14:28:22 +0000259.. method:: SMTP.has_extn(name)
260
261 Return :const:`True` if *name* is in the set of SMTP service extensions returned
262 by the server, :const:`False` otherwise. Case is ignored.
263
264
265.. method:: SMTP.verify(address)
266
267 Check the validity of an address on this server using SMTP ``VRFY``. Returns a
268 tuple consisting of code 250 and a full :rfc:`822` address (including human
269 name) if the user address is valid. Otherwise returns an SMTP error code of 400
270 or greater and an error string.
271
272 .. note::
273
274 Many sites disable SMTP ``VRFY`` in order to foil spammers.
275
276
277.. method:: SMTP.login(user, password)
278
279 Log in on an SMTP server that requires authentication. The arguments are the
280 username and the password to authenticate with. If there has been no previous
281 ``EHLO`` or ``HELO`` command this session, this method tries ESMTP ``EHLO``
282 first. This method will return normally if the authentication was successful, or
283 may raise the following exceptions:
284
285 :exc:`SMTPHeloError`
286 The server didn't reply properly to the ``HELO`` greeting.
287
288 :exc:`SMTPAuthenticationError`
289 The server didn't accept the username/password combination.
290
291 :exc:`SMTPException`
292 No suitable authentication method was found.
293
294
Antoine Pitroue0650202011-05-18 18:03:09 +0200295.. method:: SMTP.starttls(keyfile=None, certfile=None, context=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000296
297 Put the SMTP connection in TLS (Transport Layer Security) mode. All SMTP
298 commands that follow will be encrypted. You should then call :meth:`ehlo`
299 again.
300
301 If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket`
302 module's :func:`ssl` function.
303
Antoine Pitroue0650202011-05-18 18:03:09 +0200304 Optional *context* parameter is a :class:`ssl.SSLContext` object; This is an alternative to
305 using a keyfile and a certfile and if specified both *keyfile* and *certfile* should be None.
306
Christian Heimes679db4a2008-01-18 09:56:22 +0000307 If there has been no previous ``EHLO`` or ``HELO`` command this session,
308 this method tries ESMTP ``EHLO`` first.
309
Christian Heimes679db4a2008-01-18 09:56:22 +0000310 :exc:`SMTPHeloError`
311 The server didn't reply properly to the ``HELO`` greeting.
312
313 :exc:`SMTPException`
314 The server does not support the STARTTLS extension.
315
Christian Heimes679db4a2008-01-18 09:56:22 +0000316 :exc:`RuntimeError`
Ezio Melotti0639d5a2009-12-19 23:26:38 +0000317 SSL/TLS support is not available to your Python interpreter.
Christian Heimes679db4a2008-01-18 09:56:22 +0000318
Antoine Pitroue0650202011-05-18 18:03:09 +0200319 .. versionchanged:: 3.3
320 *context* was added.
321
Christian Heimesa5768f72013-12-02 20:44:17 +0100322 .. versionchanged:: 3.4
323 The method now supports hostname check with
324 :attr:`SSLContext.check_hostname` and *Server Name Indicator* (see
325 :data:`~ssl.HAS_SNI`).
326
Georg Brandl116aa622007-08-15 14:28:22 +0000327
Georg Brandl18244152009-09-02 20:34:52 +0000328.. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_options=[])
Georg Brandl116aa622007-08-15 14:28:22 +0000329
330 Send mail. The required arguments are an :rfc:`822` from-address string, a list
331 of :rfc:`822` to-address strings (a bare string will be treated as a list with 1
332 address), and a message string. The caller may pass a list of ESMTP options
333 (such as ``8bitmime``) to be used in ``MAIL FROM`` commands as *mail_options*.
334 ESMTP options (such as ``DSN`` commands) that should be used with all ``RCPT``
335 commands can be passed as *rcpt_options*. (If you need to use different ESMTP
336 options to different recipients you have to use the low-level methods such as
337 :meth:`mail`, :meth:`rcpt` and :meth:`data` to send the message.)
338
339 .. note::
340
341 The *from_addr* and *to_addrs* parameters are used to construct the message
R. David Murray7dff9e02010-11-08 17:15:13 +0000342 envelope used by the transport agents. ``sendmail`` does not modify the
Georg Brandl116aa622007-08-15 14:28:22 +0000343 message headers in any way.
344
Benjamin Petersona6c4a102011-12-30 23:08:09 -0600345 *msg* may be a string containing characters in the ASCII range, or a byte
R. David Murray7dff9e02010-11-08 17:15:13 +0000346 string. A string is encoded to bytes using the ascii codec, and lone ``\r``
Benjamin Petersona6c4a102011-12-30 23:08:09 -0600347 and ``\n`` characters are converted to ``\r\n`` characters. A byte string is
348 not modified.
R. David Murray7dff9e02010-11-08 17:15:13 +0000349
Georg Brandl116aa622007-08-15 14:28:22 +0000350 If there has been no previous ``EHLO`` or ``HELO`` command this session, this
351 method tries ESMTP ``EHLO`` first. If the server does ESMTP, message size and
352 each of the specified options will be passed to it (if the option is in the
353 feature set the server advertises). If ``EHLO`` fails, ``HELO`` will be tried
354 and ESMTP options suppressed.
355
356 This method will return normally if the mail is accepted for at least one
Georg Brandl7cb13192010-08-03 12:06:29 +0000357 recipient. Otherwise it will raise an exception. That is, if this method does
358 not raise an exception, then someone should get your mail. If this method does
359 not raise an exception, it returns a dictionary, with one entry for each
Georg Brandl116aa622007-08-15 14:28:22 +0000360 recipient that was refused. Each entry contains a tuple of the SMTP error code
361 and the accompanying error message sent by the server.
362
363 This method may raise the following exceptions:
364
365 :exc:`SMTPRecipientsRefused`
366 All recipients were refused. Nobody got the mail. The :attr:`recipients`
367 attribute of the exception object is a dictionary with information about the
368 refused recipients (like the one returned when at least one recipient was
369 accepted).
370
371 :exc:`SMTPHeloError`
372 The server didn't reply properly to the ``HELO`` greeting.
373
374 :exc:`SMTPSenderRefused`
375 The server didn't accept the *from_addr*.
376
377 :exc:`SMTPDataError`
378 The server replied with an unexpected error code (other than a refusal of a
379 recipient).
380
381 Unless otherwise noted, the connection will be open even after an exception is
382 raised.
383
Georg Brandl61063cc2012-06-24 22:48:30 +0200384 .. versionchanged:: 3.2
385 *msg* may be a byte string.
R. David Murray7dff9e02010-11-08 17:15:13 +0000386
387
R David Murrayac4e5ab2011-07-02 21:03:19 -0400388.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, \
389 mail_options=[], rcpt_options=[])
R. David Murray7dff9e02010-11-08 17:15:13 +0000390
391 This is a convenience method for calling :meth:`sendmail` with the message
392 represented by an :class:`email.message.Message` object. The arguments have
393 the same meaning as for :meth:`sendmail`, except that *msg* is a ``Message``
394 object.
395
R David Murrayac4e5ab2011-07-02 21:03:19 -0400396 If *from_addr* is ``None`` or *to_addrs* is ``None``, ``send_message`` fills
397 those arguments with addresses extracted from the headers of *msg* as
398 specified in :rfc:`2822`\: *from_addr* is set to the :mailheader:`Sender`
399 field if it is present, and otherwise to the :mailheader:`From` field.
400 *to_adresses* combines the values (if any) of the :mailheader:`To`,
401 :mailheader:`Cc`, and :mailheader:`Bcc` fields from *msg*. If exactly one
402 set of :mailheader:`Resent-*` headers appear in the message, the regular
403 headers are ignored and the :mailheader:`Resent-*` headers are used instead.
404 If the message contains more than one set of :mailheader:`Resent-*` headers,
405 a :exc:`ValueError` is raised, since there is no way to unambiguously detect
406 the most recent set of :mailheader:`Resent-` headers.
407
408 ``send_message`` serializes *msg* using
R. David Murray7dff9e02010-11-08 17:15:13 +0000409 :class:`~email.generator.BytesGenerator` with ``\r\n`` as the *linesep*, and
R David Murrayac4e5ab2011-07-02 21:03:19 -0400410 calls :meth:`sendmail` to transmit the resulting message. Regardless of the
411 values of *from_addr* and *to_addrs*, ``send_message`` does not transmit any
412 :mailheader:`Bcc` or :mailheader:`Resent-Bcc` headers that may appear
413 in *msg*.
R. David Murray7dff9e02010-11-08 17:15:13 +0000414
415 .. versionadded:: 3.2
416
Georg Brandl116aa622007-08-15 14:28:22 +0000417
418.. method:: SMTP.quit()
419
Christian Heimesba4af492008-03-28 00:55:15 +0000420 Terminate the SMTP session and close the connection. Return the result of
421 the SMTP ``QUIT`` command.
422
Georg Brandl116aa622007-08-15 14:28:22 +0000423
424Low-level methods corresponding to the standard SMTP/ESMTP commands ``HELP``,
425``RSET``, ``NOOP``, ``MAIL``, ``RCPT``, and ``DATA`` are also supported.
426Normally these do not need to be called directly, so they are not documented
427here. For details, consult the module code.
428
429
430.. _smtp-example:
431
432SMTP Example
433------------
434
435This example prompts the user for addresses needed in the message envelope ('To'
436and 'From' addresses), and the message to be delivered. Note that the headers
437to be included with the message must be included in the message as entered; this
438example doesn't do any processing of the :rfc:`822` headers. In particular, the
439'To' and 'From' addresses must be included in the message headers explicitly. ::
440
441 import smtplib
442
Georg Brandl116aa622007-08-15 14:28:22 +0000443 def prompt(prompt):
Georg Brandl8d5c3922007-12-02 22:48:17 +0000444 return input(prompt).strip()
Georg Brandl116aa622007-08-15 14:28:22 +0000445
446 fromaddr = prompt("From: ")
447 toaddrs = prompt("To: ").split()
Georg Brandl6911e3c2007-09-04 07:15:32 +0000448 print("Enter message, end with ^D (Unix) or ^Z (Windows):")
Georg Brandl116aa622007-08-15 14:28:22 +0000449
450 # Add the From: and To: headers at the start!
451 msg = ("From: %s\r\nTo: %s\r\n\r\n"
452 % (fromaddr, ", ".join(toaddrs)))
Collin Winter46334482007-09-10 00:49:57 +0000453 while True:
Georg Brandl116aa622007-08-15 14:28:22 +0000454 try:
Georg Brandl8d5c3922007-12-02 22:48:17 +0000455 line = input()
Georg Brandl116aa622007-08-15 14:28:22 +0000456 except EOFError:
457 break
458 if not line:
459 break
460 msg = msg + line
461
Georg Brandl6911e3c2007-09-04 07:15:32 +0000462 print("Message length is", len(msg))
Georg Brandl116aa622007-08-15 14:28:22 +0000463
464 server = smtplib.SMTP('localhost')
465 server.set_debuglevel(1)
466 server.sendmail(fromaddr, toaddrs, msg)
467 server.quit()
468
Benjamin Petersonfa0d7032009-06-01 22:42:33 +0000469.. note::
470
471 In general, you will want to use the :mod:`email` package's features to
R. David Murray7dff9e02010-11-08 17:15:13 +0000472 construct an email message, which you can then send
473 via :meth:`~smtplib.SMTP.send_message`; see :ref:`email-examples`.