Module smtplib
[hide private]
[frames] | no frames]

Module smtplib

SMTP/ESMTP client class.

This should follow RFC 821 (SMTP), RFC 1869 (ESMTP), RFC 2554 (SMTP Authentication) and RFC 2487 (Secure SMTP over TLS).

Notes:

Please remember, when doing ESMTP, that the names of the SMTP service extensions are NOT the same thing as the option keywords for the RCPT and MAIL commands!

Example:

>>> import smtplib
>>> s=smtplib.SMTP("localhost")
>>> print s.help()
This is Sendmail version 8.8.4
Topics:
    HELO    EHLO    MAIL    RCPT    DATA
    RSET    NOOP    QUIT    HELP    VRFY
    EXPN    VERB    ETRN    DSN
For more info use "HELP <topic>".
To report bugs in the implementation send email to
    sendmail-bugs@sendmail.org.
For local information send email to Postmaster at your site.
End of HELP info
>>> s.putcmd("vrfy","someone@here")
>>> s.getreply()
(250, "Somebody OverHere <somebody@here.my.org>")
>>> s.quit()
Classes [hide private]
SMTPException
Base class for all exceptions raised by this module.
SMTPServerDisconnected
Not connected to any SMTP server.
SMTPResponseException
Base class for all exceptions that include an SMTP error code.
SMTPSenderRefused
Sender address refused.
SMTPRecipientsRefused
All recipient addresses refused.
SMTPDataError
The SMTP server didn't accept the data.
SMTPConnectError
Error during connection establishment.
SMTPHeloError
The server refused our HELO reply.
SMTPAuthenticationError
Authentication error.
SSLFakeSocket
A fake socket object that really wraps a SSLObject.
SSLFakeFile
A fake file like object that really wraps a SSLObject.
SMTP
This class manages a connection to an SMTP or ESMTP server.
Functions [hide private]
 
quoteaddr(addr)
Quote a subset of the email addresses defined by RFC 821.
 
quotedata(data)
Quote data for email.
Variables [hide private]
  SMTP_PORT = 25
  CRLF = '\r\n'
  OLDSTYLE_AUTH = re.compile(r'(?i)auth=(.*)')

Imports: socket, re, email, base64, hmac, encode_base64, stderr


Function Details [hide private]

quoteaddr(addr)

 

Quote a subset of the email addresses defined by RFC 821.

Should be able to handle anything rfc822.parseaddr can handle.

quotedata(data)

 

Quote data for email.

Double leading '.', and change Unix newline '\n', or Mac '\r' into Internet CRLF end-of-line.