#!/usr/bin/python
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.
"""
try:
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')