ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH

Reference
ActivePython 2.5
Python Documentation
Library Reference
18. Internet Protocols and Support
18.1 webbrowser -- Convenient Web-browser controller
18.2 cgi -- Common Gateway Interface support.
18.3 cgitb -- Traceback manager for CGI scripts
18.4 wsgiref -- WSGI Utilities and Reference Implementation
18.5 urllib -- Open arbitrary resources by URL
18.6 urllib2 -- extensible library for opening URLs
18.7 httplib -- HTTP protocol client
18.8 ftplib -- FTP protocol client
18.9 gopherlib -- Gopher protocol client
18.10 poplib -- POP3 protocol client
18.11 imaplib -- IMAP4 protocol client
18.12 nntplib -- NNTP protocol client
18.13 smtplib -- SMTP protocol client
18.13.1 SMTP Objects
18.13.2 SMTP Example
18.14 smtpd -- SMTP Server
18.15 telnetlib -- Telnet client
18.16 uuid -- UUID objects according to RFC 4122
18.17 urlparse -- Parse URLs into components
18.18 SocketServer -- A framework for network servers
18.19 BaseHTTPServer -- Basic HTTP server
18.20 SimpleHTTPServer -- Simple HTTP request handler
18.21 CGIHTTPServer -- CGI-capable HTTP request handler
18.22 cookielib -- Cookie handling for HTTP clients
18.23 Cookie -- HTTP state management
18.24 xmlrpclib -- XML-RPC client access
18.25 SimpleXMLRPCServer -- Basic XML-RPC server
18.26 DocXMLRPCServer -- Self-documenting XML-RPC server

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 18. Internet Protocols and Support
ActivePython 2.5 documentation

18.13 smtplib -- SMTP protocol client

The smtplib module defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon. For details of SMTP and ESMTP operation, consult RFC 821 (Simple Mail Transfer Protocol) and RFC 1869 (SMTP Service Extensions).

class SMTP( [host[, port[, local_hostname]]])
A SMTP instance encapsulates an SMTP connection. It has methods that support a full repertoire of SMTP and ESMTP operations. If the optional host and port parameters are given, the SMTP connect() method is called with those parameters during initialization. An SMTPConnectError is raised if the specified host doesn't respond correctly.

For normal use, you should only require the initialization/connect, sendmail(), and quit() methods. An example is included below.

A nice selection of exceptions is defined as well:

exception SMTPException
Base exception class for all exceptions raised by this module.

exception SMTPServerDisconnected
This exception is raised when the server unexpectedly disconnects, or when an attempt is made to use the SMTP instance before connecting it to a server.

exception SMTPResponseException
Base class for all exceptions that include an SMTP error code. These exceptions are generated in some instances when the SMTP server returns an error code. The error code is stored in the smtp_code attribute of the error, and the smtp_error attribute is set to the error message.

exception SMTPSenderRefused
Sender address refused. In addition to the attributes set by on all SMTPResponseException exceptions, this sets `sender' to the string that the SMTP server refused.

exception SMTPRecipientsRefused
All recipient addresses refused. The errors for each recipient are accessible through the attribute recipients, which is a dictionary of exactly the same sort as SMTP.sendmail() returns.

exception SMTPDataError
The SMTP server refused to accept the message data.

exception SMTPConnectError
Error occurred during establishment of a connection with the server.

exception SMTPHeloError
The server refused our "HELO" message.

exception SMTPAuthenticationError
SMTP authentication went wrong. Most probably the server didn't accept the username/password combination provided.

See Also:

RFC 821, Simple Mail Transfer Protocol
Protocol definition for SMTP. This document covers the model, operating procedure, and protocol details for SMTP.
RFC 1869, SMTP Service Extensions
Definition of the ESMTP extensions for SMTP. This describes a framework for extending SMTP with new commands, supporting dynamic discovery of the commands provided by the server, and defines a few additional commands.



See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved