7.15 The smtplib Module
The smtplib module (shown in Example 7-30) provides a Simple Mail Transfer
Protocol (SMTP) client implementation. This protocol is
used to send mail through Unix mail servers.
To read mail, use the poplib or imaplib modules.
Example 7-30. Using the smtplib Module
File: smtplib-example-1.py
import smtplib
import string, sys
HOST = "localhost"
FROM = "[email protected]"
TO = "[email protected]"
SUBJECT = "for your information!"
BODY = "next week: how to fling an otter"
body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")
print body
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], body)
server.quit()
From: [email protected]
To: [email protected]
Subject: for your information!
next week: how to fling an otter
|