By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,636 Members | 1,814 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,636 IT Pros & Developers. It's quick & easy.

Problem using smtplib.SMTP in a CGI program

P: n/a
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('m*@foresoft.co.uk', ['y**@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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
[df*@forestfield.co.uk (David Hughes)]:
SMTPhost = auth.smtp.oneandone.co.uk [...]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.


I don't know about 'www.oneandone.co.uk' but I know what helped
at 'www.1und1.de'. The problem is that they simply don't allow
smtp-access from within.

On http://faq.1und1.de/hosting/skripte_.../python/3.html 1und1
advises you to use:

#!/usr/bin/python
import os
print "Content-Type: text/plain"
print
Mailto= "em********@musterfrau.de"
Mailfrom = "ab******@musterfrau.de"
Subject = "Betreff"
Header = """From: %s
To: %s
Subject: %s
""" % (Mailfrom, Mailto, Subject)
msg = Header + " Dies ist eine Test-Mail "
sendmail = os.popen("/usr/lib/sendmail -t", "w")
sendmail.write(msg)
sendmail.close()

hope this helps,

mb - Martin Bless

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.