connect in SMTPlib
Steve Holden
sholden at holdenweb.com
Mon Jul 16 09:21:49 EDT 2001
More information about the Python-list mailing list
Mon Jul 16 09:21:49 EDT 2001
- Previous message (by thread): connect in SMTPlib
- Next message (by thread): got winioport.zip from http://www.geocities.com/dinceraydin/ now what?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Look in the Vaults of Parnassus, and use timeoutsocket to handle such scket timeouts in a more friendly way. regards Steve -- http://www.holdenweb.com/ "Rajkumar S." <raj2569 at yahoo.com> wrote in message news:mailman.995224946.25425.python-list at python.org... > Hi all, > > I am writing cgi program to send a mail of all the selection made by > the user to admin. The from addr and to addr are fixed in the script. > One of the probable error that I see is that of the SMTP server being > down. Their are no exceptions defined for the connect(). So the script > bombs when the connect fails and gives the 500 error. > > Can the script be made more robust esp when faced by a down SMTP > server? > > raj > > #!/usr/local/bin/python > import smtplib > import string > import cgi > > fromaddr = "xxx <xx at xx.com>" > toaddrs = "xxx <xx.com>" > > thankyou = '''Content-Type: text/html\n\n > <html> > <head> <title> Thank You!</title> </head> > <body> > Thank you !! > </body> > </html>''' > > error = '''Content-Type: text/html\n\n > <html> > <head> <title> We are sorry</title> </head> > <body> > We are extremely sorry that an error had occured while sending mail. > </body>''' > > form = cgi.FieldStorage() > formkeys = form.keys() > > <snip> > </snip> > > msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (fromaddr, toaddrs, order)) > line = msg + line > > server = smtplib.SMTP('localhost') > > try: > server.sendmail(fromaddr, toaddrs, line) > except smtplib.SMTPException: > print error > server.quit() > server.quit() > print thankyou > >
- Previous message (by thread): connect in SMTPlib
- Next message (by thread): got winioport.zip from http://www.geocities.com/dinceraydin/ now what?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list