Pages

Python question on sending e-mail msg

I’m trying to use your example code for sending an e-mail message with Python. I’m getting an error message and I assume I’m missing something very simple and basic, but I can’t see it.

The code I enter into IDLE and the results back are as follows:

>>> import smtplib
>>> smtpserver = ‘mail.HennepinPublicHealth.org’
>>> AUTHREQUIRED = 1
>>> smtpuser = ‘TheUSERID’
>>> smtppass = ‘ThePassword
>>> RECIPIENTS = ['ulandreman@msn.com']
>>> SENDER = ‘urban.landreman@co.hennepin.mn.us’
>>> mssg = ‘This is a test message.’
>>> session = smtplib.SMTP(smtpserver)

Traceback (most recent call last):
File “ “, line 1, in -toplevel-
session = smtplib.SMTP(smtpserver)
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’ve changed the User ID and password to some dummy ones for this posting, but I think the error comes from the
session = smtplib.SMTP(smtpserver) line.

Any ideas?

Urban Landreman

1 comment to Python question on sending e-mail msg

  • This error message:
    error: (10054, ‘Connection reset by peer’)

    Says that the mail server is not accepting your connection.

    Referring to the smtplib documentation you might want to set the debuglevel to a non-false value so you could get more info…or try testing your connection using a method other than Python to ensure you can even make a valid connection to the STMP server from the computer that you are using.

    Right now, I’d focus on testing the connection by some other non-Python method to rule that out, before worrying more about the Python coding.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>