import smtplib
fromaddress = '[email protected]'
toaddress = [fromaddress]
message = """
From: %s
To: %s
Subject: test
Hello
Goodbye
""" % ( fromaddress, toaddress)
server = smtplib.SMTP('mydomain.com')
server.set_debuglevel(1)
server.sendmail(fromaddress, toaddress, message)
This code opens a socket ok but then fails on sendmail with a ' Connection unexpectedly closed ' error. From looking at the smtplib source this occurs when an empty response is returned from the smtp server.
What am I missing from the above code? I'm running this on a cheapy webhost as a cgi script and as part of their service they have sendmail and python services installed. In their docs they have the standard 'send an email in php' code example with no authentication needed so I'm supposing the same should work for python.
Anyone have any insight? The host is hostgator if it helps.
EDIT:
The underlying error is the smtp server issuing a hard reset ie TCP 'Connection reset by peer'. In what circumstances would an email server do this?