[Tutor] Can Anyone help with SMTP processiing

Peter Meagher ppmeagher at gmail.com
Sat Apr 17 11:40:32 CEST 2010


Greetings,

 

I'm a newbie with Python. Passable with other languages e.g.
Basic, C++ and others.  

 

Not a programmer per se, just trying to get work done that
happens to require some programming skills and want to try
my hand with Python.

 

Email processing and parsing is the focus of my tasks at
present.

 

Therefore, to get started,  I tried the following code
copied and pasted from 

 

http://docs.python.org/library/smtplib.html

 

First time through, I got the prompts indicated in the code,
except when I entered the ctrl Z nothing happened.

 

The next time and subsequent times, thereafter I get the
following 2 pop up message windows:

 

 

IDLE Sub process Error

Socket error: No connection could be made because the target
machine actively refused it

 

Sub process Startup Error

IDLE's sub process didn't make connection. Either IDLE can't
start a sub process or personal firewall software is
blocking the connection

 

Code copied and pasted from
http://docs.python.org/library/smtplib.html  is:

 

----------------------------------BEGIN CODE

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()

---------------------------------END CODE

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100417/8c34c699/attachment-0001.html>


More information about the Tutor mailing list