POP mailbox downloader : SMTP : Network PYTHON TUTORIALS


PYTHON TUTORIALS » Network » SMTP »

 

POP mailbox downloader


import getpass, poplib, sys, email

host  = "server.com"
user  = "userName"
dest  = "address"
passwd = "password"

destfd = open(dest, "at")

p = poplib.POP3(host)
try:
    p.user(user)
    p.pass_(passwd)
except poplib.error_proto, e:
    print e
    sys.exit(1)

for item in p.list()[1]:
    number, octets = item.split(' ')
    print "Downloading message %s (%s bytes)" (number, octets)
    lines = p.retr(number)[1]
    msg = email.message_from_string("n".join(lines))
    destfd.write(msg.as_string(unixfrom = 1))

p.quit()
destfd.close()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Network
» SMTP