newbie: raise socket.error, msg in smtplib

Mark Carter cartermark46 at
Tue Apr 15 13:44:25 CEST 2003

I'm getting

Traceback (most recent call last):
  File "C:\My Documents\", line 26, in ?
  File "C:\PYTHON22\lib\", line 283, in connect
    raise socket.error, msg
error: (10061, 'Connection refused')

from running a slightly modified version of the email example in the docs using
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32

What are the likely causes of this problem?

source code begin:

# Import smtplib for the actual sending function
import smtplib

# Here are the email pacakge modules we'll need
from email import Encoders
from email.MIMEText import MIMEText
# Open a plain text file for reading
textfile = 'msg.txt'
fp = open(textfile)
# Create a text/plain message, using Quoted-Printable encoding for non-ASCII
# characters.
msg = MIMEText(, _encoder=Encoders.encode_quopri)

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
me = "cartermark46 at"
you = me
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server.  Use msg.as_string() with
# unixfrom=0 so as not to confuse SMTP.
s = smtplib.SMTP()
s.connect()  ######## LINE 26
s.sendmail(me, [you], msg.as_string(0))

More information about the Python-list mailing list