import smtplib

sender = 'from@fromdomain.com'
receivers = ['to@todomain.com']

message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
Subject: SMTP e-mail test

This is a test e-mail message.

   smtpObj = smtplib.SMTP('smtp.gmail.com')
   smtpObj.sendmail(sender, receivers, message)
   print "Successfully sent email"
except smtplib.SMTPException:
   print "Error: unable to send email"

I get the following error when I try to run the script.

Traceback (most recent call last):
File "<string>", line 244, in run_nodebug
File "C:\Python Rules\scripts\module4.py", line 16, in ?
smtpObj = smtplib.SMTP('smtp.gmail.com')
File "C:\Python23\Lib\smtplib.py", line 240, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python23\Lib\smtplib.py", line 303, in connect
(code, msg) = self.getreply()
File "C:\Python23\Lib\smtplib.py", line 344, in getreply
line = self.file.readline()
File "C:\Python23\Lib\socket.py", line 338, in readline
data = self._sock.recv(self._rbufsize)
socket.error: (10054, 'Connection reset by peer')

Recommended Answers

All 3 Replies

Did you read my code snippet of sending gmail? Compare it with yours, it works.

I haven't read your code snippet. Could you direct me to the link or post the code here??


Quickest you find it by clicking my user name and clicking the code snippet link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.