retrieveing mail from a pop3 account

jesse at multimediacollective.com jesse at multimediacollective.com
Thu Jul 27 13:38:49 EDT 2000


Hey, I've been writing a program which connects to my Pop3 mail 
account, logs in, retrieves each mail in order and prints them out.  
(just printing to standard output for now).  However, say I have two 
messages in my mailbox.  It will print out the body of the first 
message TWICE.  So it will use the first body message as the body of 
every message.  Here is the code. 

def access_mail(host, user, password):
    open_mail = poplib.POP3(host)
    open_mail.user(user)
    open_mail.pass_(password)
    numMessages = len(open_mail.list()[1])
    for index in range(numMessages):
        (server_msg, body, octets) = open_mail.retr(index)
        message_body = cStringIO.StringIO(string.join(body, '\n'))
        msg = mimetools.Message(message_body)
        print message_body.read()
    
                
if __name__=='__main__':
    if len(sys.argv)<4:
        print "Usage:", sys.argv[0], "host username password"
    else:
        access_mail(sys.argv[1], sys.argv[2], sys.argv[3])

when I try to run this it comes up with this error. 

Traceback (innermost last):
  File "<interactive input>", line 1, in ?
  File "dial.py", line 36, in access_mail
    if __name__=='__main__':
  File "C:\Program Files\Python\Lib\poplib.py", line 218, in retr
    return self._longcmd('RETR %s' % which)
  File "C:\Program Files\Python\Lib\poplib.py", line 153, in _longcmd
    return self._getlongresp()
  File "C:\Program Files\Python\Lib\poplib.py", line 132, in 
_getlongresp
    resp = self._getresp()
  File "C:\Program Files\Python\Lib\poplib.py", line 125, in _getresp
    raise error_proto(resp)
error_proto: -ERR no such msg

Any thoughts?  It is a very strange problem, and none of us seem to 
be able to figure it out. 





More information about the Python-list mailing list