Python Notes (0.14.0)

13. smtplib module

Status:in progress

The smtplib module takes its name from SMTP, the Simple Mail Transport Protocol. That’s the protocol for sending Internet mail.

13.1. Quick start

If you are running a mail server, this code allows you to send a mail:

>>> import smtplib
>>> from = 'sender@example.com'
>>> to = 'target@example.com'
>>> message = 'Subject:testing smtplib\n\nBody of the message'
>>> server = smtplib.SMTP(“localhost”, 25)
>>> server.sendmail(from, to, message)
{}

13.2. RFC2822 compliant message

Todo

check and chcnage content of this example

>>> from email import Message
>>> from email.Message import Message
>>> message = Message()
>>> message['Subject'] = 'Test'
>>> message.set_payload(‘This is the body of the message’)
>>> print str(message)
From nobody Fri Mar 25 20:08:22 2005
Subject: Test

This is the body of the message

13.3. todo

smtplib.CRLF
smtplib.LMTP
smtplib.LMTP_PORT
smtplib.OLDSTYLE_AUTH
smtplib.SMTPAuthenticationError
smtplib.SMTPConnectError
smtplib.SMTPDataError
smtplib.SMTPException
smtplib.SMTPHeloError
smtplib.SMTPRecipientsRefused
smtplib.SMTPResponseException
smtplib.SMTPSenderRefused
smtplib.SMTPServerDisconnected
smtplib.SMTP_PORT
smtplib.SMTP_SSL                 smtplib.base64
smtplib.SMTP_SSL_PORT            smtplib.email
smtplib.SSLFakeFile              smtplib.encode_base64
smtplib.hmac
smtplib.quoteaddr
smtplib.quotedata
smtplib.re
smtplib.socket
smtplib.ssl
smtplib.stderr

See also

base64 and quopri for encoding/decoding.

See also

email and mailbox to receive emails

See also

poplib and imaplib for fetching mails.