Problem using smtplib.SMTP in a CGI program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Hughes

    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.onea ndone.co.uk'
    print 'SMTPhost = %s' % smtp_host
    server = smtplib.SMTP(sm tp_host)
    print 'server = %s' % repr(server)
    ## server.login(us er, password)
    server.sendmail ('me@foresoft.c o.uk', ['you@forestfiel d.co.uk'], 'Hello')
    server.quit()


    which produces the following output:

    Test SMTP connection
    SMTPhost = auth.smtp.onean done.co.uk
    Traceback (most recent call last):
    File "/homepages/40/d69667106/htdocs/cgi-bin/test_smtp.cgi", line 13, in
    ?
    server = smtplib.SMTP(sm tp_host)
    File "/usr/lib/python2.2/smtplib.py", line 234, in __init__
    (code, msg) = self.connect(ho st, 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

  • Martin Bless

    #2
    Re: Problem using smtplib.SMTP in a CGI program

    [dfh@forestfield .co.uk (David Hughes)]:
    [color=blue]
    >SMTPhost = auth.smtp.onean done.co.uk[/color]
    [...][color=blue]
    >socket.error : (111, 'Connection refused')
    >
    >The value of SMTPhost is the one my ISP adviced me to use, it is an
    >authenticate d server requiring a user name and password and I can access
    >it using Microsoft Outlook Express without difficulty.[/color]

    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= "empfaenger@mus terfrau.de"
    Mailfrom = "absender@muste rfrau.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

    Comment

    Working...