SMTP transmission with debugging : SMTP « Network « Python Tutorial






import sys, smtplib, socket

server = "server.com"
fromaddr = "frolm@from.com"
toaddrs = "to@to.com"

message = """To: %s
From: %s
Subject: Test Message

Hello,

This is a test message.
""" % (', '.join(toaddrs), fromaddr)

try:
    s = smtplib.SMTP(server)
    s.set_debuglevel(1)
    s.sendmail(fromaddr, toaddrs, message)
except (socket.gaierror, socket.error, socket.herror, smtplib.SMTPException), e:
    print e
    sys.exit(1)
else:
    print "sent"








21.11.SMTP
21.11.1.Sending Email Using SMTP
21.11.2.Retrieving Email from a POP3 Server
21.11.3.SMTP and POP3 Example
21.11.4.SMTP transmission with authentication
21.11.5.Basic SMTP transmission
21.11.6.SMTP transmission with debugging
21.11.7.POP mailbox downloader
21.11.8.POP mailbox scanning
21.11.9.POP connection and authentication
21.11.10.POP connection and authentication with APOP