SMTP transmission with authentication : SMTP : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » SMTP »

 

SMTP transmission with authentication


import sys, smtplib, socket
from getpass import getpass

server = "email.Server.com"
fromaddr = "from@from.com"
toaddrs = "to@to.com"

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

Hello,

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

username = "user name"
password = "password"

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



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» SMTP