Problem using smtplib.SMTP in a CGI program

David Hughes dfh at forestfield.co.uk
Fri Mar 19 05:58:00 EST 2004


I wonder if anyone can help me resolve this problem. Although my ISP (One 
and One) provides the facility to run Python 2.2 CGI programs, their 
technical support people don't seem to have any Python expertise.

I am trying to run Gypsymail.py as a CGI program from a web form. It is 
nearly all working, except for the part that I have reduced to the 
following code:

#!/usr/bin/python
# the line above must contain the path to Python on your web server
import sys, os, smtplib

sys.stderr = sys.stdout

print "Content-Type: Text/plain"
print
print 'Test SMTP connection'
smtp_host =  'auth.smtp.oneandone.co.uk'
print 'SMTPhost = %s' % smtp_host
server = smtplib.SMTP(smtp_host)
print 'server = %s' % repr(server)
## server.login(user, password)
server.sendmail('me at foresoft.co.uk', ['you at forestfield.co.uk'], 'Hello')
server.quit()


which produces the following output:

Test SMTP connection
SMTPhost = auth.smtp.oneandone.co.uk
Traceback (most recent call last):
  File "/homepages/40/d69667106/htdocs/cgi-bin/test_smtp.cgi", line 13, in 
?
    server = smtplib.SMTP(smtp_host)
  File "/usr/lib/python2.2/smtplib.py", line 234, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.2/smtplib.py", line 283, in connect
    raise socket.error, msg
socket.error: (111, 'Connection refused')

The value of SMTPhost is the one my ISP adviced me to use, it is an 
authenticated server requiring a user name and password and I can access 
it using Microsoft Outlook Express without difficulty.

With thanks for any help.
Regards,

David Hughes
Forestfield Software Ltd
www.forestfield.co.uk



More information about the Python-list mailing list