newbie: raise socket.error, msg in smtplib

Mark Carter cartermark46 at ukmail.com
Tue Apr 15 07:44:25 EDT 2003


I'm getting

Traceback (most recent call last):
  File "C:\My Documents\myemail.py", line 26, in ?
    s.connect()
  File "C:\PYTHON22\lib\smtplib.py", 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(fp.read(), _encoder=Encoders.encode_quopri)
fp.close()

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of %s' % textfile
me = "cartermark46 at ukmail.com"
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))
s.close()




More information about the Python-list mailing list