A how to use POP3 question, works fine now
Raaijmakers, Vincent (IndSys, GE Interlogix)
Vincent.Raaijmakers at ge.com
Tue Feb 25 12:08:57 EST 2003
Steve,
Forget the previous question. Delete works fine now.
Forgot to look in poplib.
Vincent
-----Original Message-----
From: Steve Holden [mailto:sholden at holdenweb.com]
Sent: Monday, February 24, 2003 7:57 PM
To: python-list at python.org
Subject: Re: A how to use POP3 question
"Raaijmakers, Vincent (IndSys, GE Interlogix)" <Vincent.Raaijmakers at ge.com>
wrote in message news:mailman.1046128449.11314.python-list at python.org...
> After reading, coding, trial and error work, I have the
> feeling I'm about to create a munster of a script instead
> of something nice and clean...
>
> I would like to get a list of subjects of all my emails
> on my POP3 server.
>
> What is the easiest way to do that?
>
> Something like:
> mailbox = poplib.POP3(host) mailbox.user(userName)
> mailbox.pass_(password)
>
> return mailbox.<give me the list with subjects>
>
> Thanks for any help.
Here's an example from chapter 5 of "Python Web Programming". It might do
about what you want, or possibly a bit more:
import poplib
import rfc822, sys, StringIO
SRVR = "mymailserver.com"
USER = "user"
PASS = "password"
try:
p = poplib.POP3(SRVR)
except:
print "Unable to contact server %s" % (SRVR, )
sys.exit(-1)
try:
print p.user(USER)
print p.pass_(PASS)
except:
print "Authentication failure"
sys.exit(-2)
msglst = p.list()[1]
for m in msglst:
mno, size = m.split()
lines = p.retr(mno)[1]
print "----- Message %s --------------" % (mno, )
file = StringIO.StringIO("\r\n".join(lines))
msg = rfc822.Message(file)
body = file.readlines()
addrs = msg.getaddrlist("to")
print "%-15s %s" % ("Recipient", "Email Address")
for rcpt, addr in addrs:
print "%-15s %s" % (rcpt, addr)
print len(body), "lines in message body"
print "-------------------------------"
p.quit()
sys.exit()
regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
Register for PyCon now! http://www.python.org/pycon/reg.html
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list