473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problem using smtplib.SMTP in a CGI program

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
1 2882
[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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Frank Zheng | last post by:
I wrote some code to test "smtplib", but i met a problem when i call the "login(user,pass)" of the "SMTP" object. here are the codes: >>> s = smtplib.SMTP() >>> s.set_debuglevel(1) >>>...
0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
14
by: sridhar | last post by:
iam having user account on an exchangeserver. with that can i send an email using python? if iam using the following code iam getting error fromAddress = 'sridhar_kasturi@satyam.com'...
3
by: Erik Johnson | last post by:
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that...
8
by: NicolasG | last post by:
I'm using the following code to send e-mail through python: import smtplib fromaddr = 'myMail@gmail.com' toaddrs = 'myOtherMail@gmail.com' subject = 'someting for subject !' msg = 'This...
3
by: gatoruss | last post by:
Newbie here with a (hopefully not) dumb question....tried searching around on the 'Net without success, so here goes.... I have been playing around with python. I wrote a script that sends an smtp...
1
by: Benedict Verheyen | last post by:
Hi, i get an "Unable to relay for" when trying to send an email from within my network to an email address not on my domain. I don't understand why it says "relaying" as i'm sending from an...
1
by: the_ricka | last post by:
Hi all, I'm fairly new to python, but very excited about it's potential. I'm trying to write a simple program that will accept input from a command line and send email. The parameters I used on...
5
by: sui | last post by:
this is my code import sys, os, glob, datetime, time import smtplib ## Parameters for SMTP session port=587 SMTPserver= 'smtp.gmail.com' SMTPuser= '...@gmail.com' pw= 'fill in here'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.