Outgoing mail problems


#1

Hello,

I have a problem involving sending out email using a python script. My python script works fine when configured for another mailserver I own, but when I use my dreamhost mail server I get weird behavior. For dreamhost, it sends the first time I try, but then every attempt after that it says socket.error: (104, ‘Connection reset by peer’). After waiting 24 hours, again I was able to send a message, and then all attempts after that one had the same error socket.error: (104, ‘Connection reset by peer’).

Any hints would be helpful. Dreamhost support tells me this is a script problem and they can’t help me.

Thanks, Matt

===== SCRIPT =====

#!/usr/bin/env python

import config,smtplib
from email.MIMEMultipart import MIMEMultipart
from email.Utils import formatdate
from email.MIMEText import MIMEText

config=dict(PORT=25,MAILSERVER=‘mail.mydomain.com’,MS_USERNAME=‘contact@mydomain.com’,MS_PASSWORD=‘mypassword’)

fr='contact@mydomain.com’
to=‘myemail@address.com’

msg = MIMEMultipart()
msg[‘From’] = fr
msg[‘To’] = to
msg[‘Date’] = formatdate(localtime=True)
msg[‘Subject’] = 'subject’
msg.attach(MIMEText(‘hello world’))

smtp = smtplib.SMTP()
smtp.connect(config[‘MAILSERVER’],config[‘PORT’])
smtp.login(config[‘MS_USERNAME’],config[‘MS_PASSWORD’])
smtp.sendmail(fr,to,msg.as_string())
smtp.close()