blob: eba8ae9278d51e4f47621edc65da15de720b47dd [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
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +000025 A :class:`SMTP` instance encapsulates an SMTP connection. It has methods
26 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
35 setting will be used). The optional source_address parameter allows to bind
36 to some specific source address in a machine with multiple network
37 interfaces, and/or to some specific source TCP port. It takes a 2-tuple
38 (host, port), for the socket to bind to as its source address before
39 connecting. If omitted (or if host or port are ``''`` and/or 0 respectively)
40 the OS default behavior will be used.
Georg Brandl116aa622007-08-15 14:28:22 +000041
42 For normal use, you should only require the initialization/connect,
Jesus Ceac73f8632012-12-26 16:47:03 +010043 :meth:`sendmail`, and :meth:`~smtplib.quit` methods.
44 An example is included below.
Georg Brandl116aa622007-08-15 14:28:22 +000045
Barry Warsaw1f5c9582011-03-15 15:04:44 -040046 The :class:`SMTP` class supports the :keyword:`with` statement. When used
47 like this, the SMTP ``QUIT`` command is issued automatically when the
48 :keyword:`with` statement exits. E.g.::
49
50 >>> from smtplib import SMTP
51 >>> with SMTP("domain.org") as smtp:
52 ... smtp.noop()
53 ...
54 (250, b'Ok')
55 >>>
56
Antoine Pitrou45456a02011-04-26 18:53:42 +020057 .. versionchanged:: 3.3
Barry Warsaw1f5c9582011-03-15 15:04:44 -040058 Support for the :keyword:`with` statement was added.
59
Senthil Kumaranb351a482011-07-31 09:14:17 +080060 .. versionchanged:: 3.3
61 source_address argument was added.
Georg Brandl116aa622007-08-15 14:28:22 +000062
R David Murray36beb662013-06-23 15:47:50 -040063.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, \
64 certfile=None [, timeout], context=None, \
65 source_address=None)
Georg Brandl116aa622007-08-15 14:28:22 +000066
67 A :class:`SMTP_SSL` instance behaves exactly the same as instances of
68 :class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +000069 required from the beginning of the connection and using :meth:`starttls` is
70 not appropriate. If *host* is not specified, the local host is used. If
R David Murray36beb662013-06-23 15:47:50 -040071 *port* is zero, the standard SMTP-over-SSL port (465) is used. The optional
72 arguments *local_hostname* and *source_address* have the same meaning as
R David Murray021362d2013-06-23 16:05:44 -040073 they do in the :class:`SMTP` class. *keyfile* and *certfile* are also
74 optional, and can contain a PEM formatted private key and certificate chain
75 file for the SSL connection. *context* also optional, can contain a
76 SSLContext, and is an alternative to keyfile and certfile; If it is
77 specified both keyfile and certfile must be None. The optional *timeout*
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +000078 parameter specifies a timeout in seconds for blocking operations like the
Georg Brandlf78e02b2008-06-10 17:40:04 +000079 connection attempt (if not specified, the global default timeout setting
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080080 will be used). The optional source_address parameter allows to bind to some
81 specific source address in a machine with multiple network interfaces,
82 and/or to some specific source tcp port. It takes a 2-tuple (host, port),
83 for the socket to bind to as its source address before connecting. If
Senthil Kumaranb351a482011-07-31 09:14:17 +080084 omitted (or if host or port are ``''`` and/or 0 respectively) the OS default
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080085 behavior will be used.
Georg Brandl116aa622007-08-15 14:28:22 +000086
Antoine Pitroue0650202011-05-18 18:03:09 +020087 .. versionchanged:: 3.3
88 *context* was added.
89
Senthil Kumaranb351a482011-07-31 09:14:17 +080090 .. versionchanged:: 3.3
91 source_address argument was added.
Georg Brandl116aa622007-08-15 14:28:22 +000092
Christian Heimesa5768f72013-12-02 20:44:17 +010093 .. versionchanged:: 3.4
94 The class now supports hostname check with
95 :attr:`SSLContext.check_hostname` and *Server Name Indicator* (see
96 :data:`~ssl.HAS_SNI`).
Senthil Kumaran3d23fd62011-07-30 10:56:50 +080097
98.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None)
Georg Brandl116aa622007-08-15 14:28:22 +000099
100 The LMTP protocol, which is very similar to ESMTP, is heavily based on the
Senthil Kumaran3d23fd62011-07-30 10:56:50 +0800101 standard SMTP client. It's common to use Unix sockets for LMTP, so our
102 :meth:`connect` method must support that as well as a regular host:port
Senthil Kumaranb351a482011-07-31 09:14:17 +0800103 server. The optional arguments local_hostname and source_address have the
R David Murray021362d2013-06-23 16:05:44 -0400104 same meaning as they do in the :class:`SMTP` class. To specify a Unix
105 socket, you must use an absolute path for *host*, starting with a '/'.
Georg Brandl116aa622007-08-15 14:28:22 +0000106
R David Murray021362d2013-06-23 16:05:44 -0400107 Authentication is supported, using the regular SMTP mechanism. When using a
108 Unix socket, LMTP generally don't support or require any authentication, but
109 your mileage might vary.
Georg Brandl116aa622007-08-15 14:28:22 +0000110
Georg Brandl116aa622007-08-15 14:28:22 +0000111
112A nice selection of exceptions is defined as well:
113
114
115.. exception:: SMTPException
116
R David Murray8a345962013-04-14 06:46:35 -0400117 Subclass of :exc:`OSError` that is the base exception class for all
Ned Deily7cf5e612013-08-13 01:15:14 -0700118 the other exceptions provided by this module.
Georg Brandl116aa622007-08-15 14:28:22 +0000119
120
121.. exception:: SMTPServerDisconnected
122
123 This exception is raised when the server unexpectedly disconnects, or when an
124 attempt is made to use the :class:`SMTP` instance before connecting it to a
125 server.
126
127
128.. exception:: SMTPResponseException
129
130 Base class for all exceptions that include an SMTP error code. These exceptions
131 are generated in some instances when the SMTP server returns an error code. The
132 error code is stored in the :attr:`smtp_code` attribute of the error, and the
133 :attr:`smtp_error` attribute is set to the error message.
134
135
136.. exception:: SMTPSenderRefused
137
138 Sender address refused. In addition to the attributes set by on all
139 :exc:`SMTPResponseException` exceptions, this sets 'sender' to the string that
140 the SMTP server refused.
141
142
143.. exception:: SMTPRecipientsRefused
144
145 All recipient addresses refused. The errors for each recipient are accessible
146 through the attribute :attr:`recipients`, which is a dictionary of exactly the
147 same sort as :meth:`SMTP.sendmail` returns.
148
149
150.. exception:: SMTPDataError
151
152 The SMTP server refused to accept the message data.
153
154
155.. exception:: SMTPConnectError
156
157 Error occurred during establishment of a connection with the server.
158
159
160.. exception:: SMTPHeloError
161
162 The server refused our ``HELO`` message.
163
164
165.. exception:: SMTPAuthenticationError
166
167 SMTP authentication went wrong. Most probably the server didn't accept the
168 username/password combination provided.
169
170
171.. seealso::
172
173 :rfc:`821` - Simple Mail Transfer Protocol
174 Protocol definition for SMTP. This document covers the model, operating
175 procedure, and protocol details for SMTP.
176
177 :rfc:`1869` - SMTP Service Extensions
178 Definition of the ESMTP extensions for SMTP. This describes a framework for
179 extending SMTP with new commands, supporting dynamic discovery of the commands
180 provided by the server, and defines a few additional commands.
181
182
183.. _smtp-objects:
184
185SMTP Objects
186------------
187
188An :class:`SMTP` instance has the following methods:
189
190
191.. method:: SMTP.set_debuglevel(level)
192
193 Set the debug output level. A true value for *level* results in debug messages
194 for connection and for all messages sent to and received from the server.
195
196
Georg Brandl18244152009-09-02 20:34:52 +0000197.. method:: SMTP.docmd(cmd, args='')
Georg Brandl116aa622007-08-15 14:28:22 +0000198
Georg Brandl18244152009-09-02 20:34:52 +0000199 Send a command *cmd* to the server. The optional argument *args* is simply
Georg Brandl116aa622007-08-15 14:28:22 +0000200 concatenated to the command, separated by a space.
201
202 This returns a 2-tuple composed of a numeric response code and the actual
203 response line (multiline responses are joined into one long line.)
204
205 In normal operation it should not be necessary to call this method explicitly.
206 It is used to implement other methods and may be useful for testing private
207 extensions.
208
209 If the connection to the server is lost while waiting for the reply,
210 :exc:`SMTPServerDisconnected` will be raised.
211
212
R David Murray14ee3cf2013-04-13 14:40:33 -0400213.. method:: SMTP.connect(host='localhost', port=0)
214
215 Connect to a host on a given port. The defaults are to connect to the local
216 host at the standard SMTP port (25). If the hostname ends with a colon (``':'``)
217 followed by a number, that suffix will be stripped off and the number
218 interpreted as the port number to use. This method is automatically invoked by
219 the constructor if a host is specified during instantiation. Returns a
220 2-tuple of the response code and message sent by the server in its
221 connection response.
222
223
Georg Brandl18244152009-09-02 20:34:52 +0000224.. method:: SMTP.helo(name='')
Georg Brandl116aa622007-08-15 14:28:22 +0000225
226 Identify yourself to the SMTP server using ``HELO``. The hostname argument
227 defaults to the fully qualified domain name of the local host.
Benjamin Petersonae5360b2008-09-08 23:05:23 +0000228 The message returned by the server is stored as the :attr:`helo_resp` attribute
229 of the object.
Georg Brandl116aa622007-08-15 14:28:22 +0000230
231 In normal operation it should not be necessary to call this method explicitly.
232 It will be implicitly called by the :meth:`sendmail` when necessary.
233
234
Georg Brandl18244152009-09-02 20:34:52 +0000235.. method:: SMTP.ehlo(name='')
Georg Brandl116aa622007-08-15 14:28:22 +0000236
237 Identify yourself to an ESMTP server using ``EHLO``. The hostname argument
238 defaults to the fully qualified domain name of the local host. Examine the
Georg Brandl48310cd2009-01-03 21:18:54 +0000239 response for ESMTP option and store them for use by :meth:`has_extn`.
240 Also sets several informational attributes: the message returned by
241 the server is stored as the :attr:`ehlo_resp` attribute, :attr:`does_esmtp`
Benjamin Petersonae5360b2008-09-08 23:05:23 +0000242 is set to true or false depending on whether the server supports ESMTP, and
243 :attr:`esmtp_features` will be a dictionary containing the names of the
244 SMTP service extensions this server supports, and their
245 parameters (if any).
Georg Brandl116aa622007-08-15 14:28:22 +0000246
247 Unless you wish to use :meth:`has_extn` before sending mail, it should not be
248 necessary to call this method explicitly. It will be implicitly called by
249 :meth:`sendmail` when necessary.
250
Christian Heimes679db4a2008-01-18 09:56:22 +0000251.. method:: SMTP.ehlo_or_helo_if_needed()
252
253 This method call :meth:`ehlo` and or :meth:`helo` if there has been no
254 previous ``EHLO`` or ``HELO`` command this session. It tries ESMTP ``EHLO``
255 first.
256
Georg Brandl1f01deb2009-01-03 22:47:39 +0000257 :exc:`SMTPHeloError`
Christian Heimes679db4a2008-01-18 09:56:22 +0000258 The server didn't reply properly to the ``HELO`` greeting.
259
Georg Brandl116aa622007-08-15 14:28:22 +0000260.. method:: SMTP.has_extn(name)
261
262 Return :const:`True` if *name* is in the set of SMTP service extensions returned
263 by the server, :const:`False` otherwise. Case is ignored.
264
265
266.. method:: SMTP.verify(address)
267
268 Check the validity of an address on this server using SMTP ``VRFY``. Returns a
269 tuple consisting of code 250 and a full :rfc:`822` address (including human
270 name) if the user address is valid. Otherwise returns an SMTP error code of 400
271 or greater and an error string.
272
273 .. note::
274
275 Many sites disable SMTP ``VRFY`` in order to foil spammers.
276
277
278.. method:: SMTP.login(user, password)
279
280 Log in on an SMTP server that requires authentication. The arguments are the
281 username and the password to authenticate with. If there has been no previous
282 ``EHLO`` or ``HELO`` command this session, this method tries ESMTP ``EHLO``
283 first. This method will return normally if the authentication was successful, or
284 may raise the following exceptions:
285
286 :exc:`SMTPHeloError`
287 The server didn't reply properly to the ``HELO`` greeting.
288
289 :exc:`SMTPAuthenticationError`
290 The server didn't accept the username/password combination.
291
292 :exc:`SMTPException`
293 No suitable authentication method was found.
294
295
Antoine Pitroue0650202011-05-18 18:03:09 +0200296.. method:: SMTP.starttls(keyfile=None, certfile=None, context=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000297
298 Put the SMTP connection in TLS (Transport Layer Security) mode. All SMTP
299 commands that follow will be encrypted. You should then call :meth:`ehlo`
300 again.
301
302 If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket`
303 module's :func:`ssl` function.
304
Antoine Pitroue0650202011-05-18 18:03:09 +0200305 Optional *context* parameter is a :class:`ssl.SSLContext` object; This is an alternative to
306 using a keyfile and a certfile and if specified both *keyfile* and *certfile* should be None.
307
Christian Heimes679db4a2008-01-18 09:56:22 +0000308 If there has been no previous ``EHLO`` or ``HELO`` command this session,
309 this method tries ESMTP ``EHLO`` first.
310
Christian Heimes679db4a2008-01-18 09:56:22 +0000311 :exc:`SMTPHeloError`
312 The server didn't reply properly to the ``HELO`` greeting.
313
314 :exc:`SMTPException`
315 The server does not support the STARTTLS extension.
316
Christian Heimes679db4a2008-01-18 09:56:22 +0000317 :exc:`RuntimeError`
Ezio Melotti0639d5a2009-12-19 23:26:38 +0000318 SSL/TLS support is not available to your Python interpreter.
Christian Heimes679db4a2008-01-18 09:56:22 +0000319
Antoine Pitroue0650202011-05-18 18:03:09 +0200320 .. versionchanged:: 3.3
321 *context* was added.
322
Christian Heimesa5768f72013-12-02 20:44:17 +0100323 .. versionchanged:: 3.4
324 The method now supports hostname check with
325 :attr:`SSLContext.check_hostname` and *Server Name Indicator* (see
326 :data:`~ssl.HAS_SNI`).
327
Georg Brandl116aa622007-08-15 14:28:22 +0000328
Georg Brandl18244152009-09-02 20:34:52 +0000329.. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_options=[])
Georg Brandl116aa622007-08-15 14:28:22 +0000330
331 Send mail. The required arguments are an :rfc:`822` from-address string, a list
332 of :rfc:`822` to-address strings (a bare string will be treated as a list with 1
333 address), and a message string. The caller may pass a list of ESMTP options
334 (such as ``8bitmime``) to be used in ``MAIL FROM`` commands as *mail_options*.
335 ESMTP options (such as ``DSN`` commands) that should be used with all ``RCPT``
336 commands can be passed as *rcpt_options*. (If you need to use different ESMTP
337 options to different recipients you have to use the low-level methods such as
338 :meth:`mail`, :meth:`rcpt` and :meth:`data` to send the message.)
339
340 .. note::
341
342 The *from_addr* and *to_addrs* parameters are used to construct the message
R. David Murray7dff9e02010-11-08 17:15:13 +0000343 envelope used by the transport agents. ``sendmail`` does not modify the
Georg Brandl116aa622007-08-15 14:28:22 +0000344 message headers in any way.
345
Benjamin Petersona6c4a102011-12-30 23:08:09 -0600346 *msg* may be a string containing characters in the ASCII range, or a byte
R. David Murray7dff9e02010-11-08 17:15:13 +0000347 string. A string is encoded to bytes using the ascii codec, and lone ``\r``
Benjamin Petersona6c4a102011-12-30 23:08:09 -0600348 and ``\n`` characters are converted to ``\r\n`` characters. A byte string is
349 not modified.
R. David Murray7dff9e02010-11-08 17:15:13 +0000350
Georg Brandl116aa622007-08-15 14:28:22 +0000351 If there has been no previous ``EHLO`` or ``HELO`` command this session, this
352 method tries ESMTP ``EHLO`` first. If the server does ESMTP, message size and
353 each of the specified options will be passed to it (if the option is in the
354 feature set the server advertises). If ``EHLO`` fails, ``HELO`` will be tried
355 and ESMTP options suppressed.
356
357 This method will return normally if the mail is accepted for at least one
Georg Brandl7cb13192010-08-03 12:06:29 +0000358 recipient. Otherwise it will raise an exception. That is, if this method does
359 not raise an exception, then someone should get your mail. If this method does
360 not raise an exception, it returns a dictionary, with one entry for each
Georg Brandl116aa622007-08-15 14:28:22 +0000361 recipient that was refused. Each entry contains a tuple of the SMTP error code
362 and the accompanying error message sent by the server.
363
364 This method may raise the following exceptions:
365
366 :exc:`SMTPRecipientsRefused`
367 All recipients were refused. Nobody got the mail. The :attr:`recipients`
368 attribute of the exception object is a dictionary with information about the
369 refused recipients (like the one returned when at least one recipient was
370 accepted).
371
372 :exc:`SMTPHeloError`
373 The server didn't reply properly to the ``HELO`` greeting.
374
375 :exc:`SMTPSenderRefused`
376 The server didn't accept the *from_addr*.
377
378 :exc:`SMTPDataError`
379 The server replied with an unexpected error code (other than a refusal of a
380 recipient).
381
382 Unless otherwise noted, the connection will be open even after an exception is
383 raised.
384
Georg Brandl61063cc2012-06-24 22:48:30 +0200385 .. versionchanged:: 3.2
386 *msg* may be a byte string.
R. David Murray7dff9e02010-11-08 17:15:13 +0000387
388
R David Murrayac4e5ab2011-07-02 21:03:19 -0400389.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, \
390 mail_options=[], rcpt_options=[])
R. David Murray7dff9e02010-11-08 17:15:13 +0000391
392 This is a convenience method for calling :meth:`sendmail` with the message
393 represented by an :class:`email.message.Message` object. The arguments have
394 the same meaning as for :meth:`sendmail`, except that *msg* is a ``Message``
395 object.
396
R David Murrayac4e5ab2011-07-02 21:03:19 -0400397 If *from_addr* is ``None`` or *to_addrs* is ``None``, ``send_message`` fills
398 those arguments with addresses extracted from the headers of *msg* as
399 specified in :rfc:`2822`\: *from_addr* is set to the :mailheader:`Sender`
400 field if it is present, and otherwise to the :mailheader:`From` field.
401 *to_adresses* combines the values (if any) of the :mailheader:`To`,
402 :mailheader:`Cc`, and :mailheader:`Bcc` fields from *msg*. If exactly one
403 set of :mailheader:`Resent-*` headers appear in the message, the regular
404 headers are ignored and the :mailheader:`Resent-*` headers are used instead.
405 If the message contains more than one set of :mailheader:`Resent-*` headers,
406 a :exc:`ValueError` is raised, since there is no way to unambiguously detect
407 the most recent set of :mailheader:`Resent-` headers.
408
409 ``send_message`` serializes *msg* using
R. David Murray7dff9e02010-11-08 17:15:13 +0000410 :class:`~email.generator.BytesGenerator` with ``\r\n`` as the *linesep*, and
R David Murrayac4e5ab2011-07-02 21:03:19 -0400411 calls :meth:`sendmail` to transmit the resulting message. Regardless of the
412 values of *from_addr* and *to_addrs*, ``send_message`` does not transmit any
413 :mailheader:`Bcc` or :mailheader:`Resent-Bcc` headers that may appear
414 in *msg*.
R. David Murray7dff9e02010-11-08 17:15:13 +0000415
416 .. versionadded:: 3.2
417
Georg Brandl116aa622007-08-15 14:28:22 +0000418
419.. method:: SMTP.quit()
420
Christian Heimesba4af492008-03-28 00:55:15 +0000421 Terminate the SMTP session and close the connection. Return the result of
422 the SMTP ``QUIT`` command.
423
Georg Brandl116aa622007-08-15 14:28:22 +0000424
425Low-level methods corresponding to the standard SMTP/ESMTP commands ``HELP``,
426``RSET``, ``NOOP``, ``MAIL``, ``RCPT``, and ``DATA`` are also supported.
427Normally these do not need to be called directly, so they are not documented
428here. For details, consult the module code.
429
430
431.. _smtp-example:
432
433SMTP Example
434------------
435
436This example prompts the user for addresses needed in the message envelope ('To'
437and 'From' addresses), and the message to be delivered. Note that the headers
438to be included with the message must be included in the message as entered; this
439example doesn't do any processing of the :rfc:`822` headers. In particular, the
440'To' and 'From' addresses must be included in the message headers explicitly. ::
441
442 import smtplib
443
Georg Brandl116aa622007-08-15 14:28:22 +0000444 def prompt(prompt):
Georg Brandl8d5c3922007-12-02 22:48:17 +0000445 return input(prompt).strip()
Georg Brandl116aa622007-08-15 14:28:22 +0000446
447 fromaddr = prompt("From: ")
448 toaddrs = prompt("To: ").split()
Georg Brandl6911e3c2007-09-04 07:15:32 +0000449 print("Enter message, end with ^D (Unix) or ^Z (Windows):")
Georg Brandl116aa622007-08-15 14:28:22 +0000450
451 # Add the From: and To: headers at the start!
452 msg = ("From: %s\r\nTo: %s\r\n\r\n"
453 % (fromaddr, ", ".join(toaddrs)))
Collin Winter46334482007-09-10 00:49:57 +0000454 while True:
Georg Brandl116aa622007-08-15 14:28:22 +0000455 try:
Georg Brandl8d5c3922007-12-02 22:48:17 +0000456 line = input()
Georg Brandl116aa622007-08-15 14:28:22 +0000457 except EOFError:
458 break
459 if not line:
460 break
461 msg = msg + line
462
Georg Brandl6911e3c2007-09-04 07:15:32 +0000463 print("Message length is", len(msg))
Georg Brandl116aa622007-08-15 14:28:22 +0000464
465 server = smtplib.SMTP('localhost')
466 server.set_debuglevel(1)
467 server.sendmail(fromaddr, toaddrs, msg)
468 server.quit()
469
Benjamin Petersonfa0d7032009-06-01 22:42:33 +0000470.. note::
471
472 In general, you will want to use the :mod:`email` package's features to
R. David Murray7dff9e02010-11-08 17:15:13 +0000473 construct an email message, which you can then send
474 via :meth:`~smtplib.SMTP.send_message`; see :ref:`email-examples`.