sending of mail (smtp) - connection refused - but smtp server is running!

Tim Williams (gmail) tdwdotnet at gmail.com
Tue Jun 29 12:30:13 EDT 2004


On Tue, 29 Jun 2004 15:26:41 +0100, Alex Hunsley
<lard at tardis.ed.ac.molar.uk> wrote:
> 
> I am using the smtp module to send emails via a local SMTP server on our network.
> I am failing with "connection refused" error, even though we definitely have an
> smtp server running on port 25!
> 
> the code is like this:
> 
>     me = 'ahunsley at companyname.com'
>     you = 'someonelse at companyname.com'
>     msg['Subject'] = '*** alert'
>     msg['From'] = me
>     msg['To'] = you
> 
>     s = smtplib.SMTP('192.168.1.105')
>     s.connect()
>     s.sendmail(me, [you], msg.as_string())
>     s.close()
> 
>     print "Email sent."
> 
> When I run this code, I get:
> 
> Traceback (most recent call last):
>   File "C:\Python23\check.py", line 58, in -toplevel-
>     s.connect()
>   File "C:\Python23\lib\smtplib.py", line 302, in connect
>     raise socket.error, msg
> error: (10061, 'Connection refused')
> 

Try this

s = smtplib.SMTP('192.168.1.105')
failed = s.sendmail(me, [you], msg.as_string())
s.quit()




More information about the Python-list mailing list