[Tutor] Smtp

Ali Polatel polatel at gmail.com
Fri May 6 12:47:09 CEST 2005


   Dear Friends,
   I tried to use the mailserver script in library reference to send
mails but it gives an error:The script and the error are below.Why
does it give this error?How can i fix?
   import smtplib

def prompt(prompt):
    return raw_input(prompt).strip()

fromaddr = prompt("From: ")
toaddrs  = prompt("To: ").split()
print "Enter message, end with ^D (Unix) or ^Z (Windows):"

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n\r\n"
       % (fromaddr, ", ".join(toaddrs)))
while 1:
    try:
        line = raw_input()
    except EOFError:
        break
    if not line:
        break
    msg = msg + line

print "Message length is " + repr(len(msg))

server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()



ERROR:

Traceback (most recent call last):
  File "D:\Python23\mailserver.py", line 26, in -toplevel-
    server.sendmail(fromaddr, toaddrs, msg)
  File "d:/python23\Lib\smtplib.py", line 676, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (550, 'Cannot connect to SMTP server localhost
(127.0.0.1:25), self connecting', 'polatel at gmail.com)


More information about the Tutor mailing list