[Tutor] Sending e-mail msg
URBAN LANDREMAN
ulandreman at msn.com
Wed May 17 17:03:43 CEST 2006
I'm trying to set up a routine to send customized e-mail messages from
records in a database.
My first step is trying to send one simple e-mail message. After I get that
figured out, I can move on to step 2.
Unfortunately, when I try the example code in the tutorials for sending
e-mail, I get error messages which I am unsure how to interpret.
The code I use is:
import smtplib
fromaddr = "urban.landreman at co.hennepin.mn.us"
toaddrs = "ulandreman at msn.com"
# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n"
% (fromaddr, toaddrs))
msg = msg + "This is a test message"
print "Message = " + msg
print "Message length is " + repr(len(msg))
server = smtplib.SMTP('mail.hennepinPublicHealth.org')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
***
The output I get is:
Message = From: urban.landreman at co.hennepin.mn.us
To: ulandreman at msn.com
This is a test message
Message length is 89
Traceback (most recent call last):
File "J:/SPSS/Python/EMailExample.py", line 14, in -toplevel-
server = smtplib.SMTP('mail.hennepinPublicHealth.org')
File "C:\Program Files\Python\lib\smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
File "C:\Program Files\Python\lib\smtplib.py", line 307, in connect
(code, msg) = self.getreply()
File "C:\Program Files\Python\lib\smtplib.py", line 348, in getreply
line = self.file.readline()
File "C:\Program Files\Python\lib\socket.py", line 340, in readline
data = self._sock.recv(self._rbufsize)
error: (10054, 'Connection reset by peer')
***
I also tried:
server = smtplib.SMTP('localhost')
with the same result.
I have checked several of the tutorials and FAQ sites and the impression
that's given is that this functionality is quite simple, so I assume that
I'm just missing one small step.
Any suggestion would be much appreciated.
Thank you.
Urban Landreman
More information about the Tutor
mailing list