| | |
Receive e-mail
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I'm really confused what you're asking. Can you explain further please?
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
I imagine you used the smtplib module and its functions to send e-mail. Well, you use the poplib module and its functions to view and delete e-mail.
Use help('poplib') to get details.
A rather crummy example is at
http://docs.python.org/lib/pop3-example.html
Use help('poplib') to get details.
A rather crummy example is at
http://docs.python.org/lib/pop3-example.html
May 'the Google' be with you!
Found code in one of the books in the CS library:
Python Syntax (Toggle Plain Text)
# view and delete e-mail using the POP3 protocol import sys, getpass, poplib, re # change according to your needs POPHOST = "pop.domain.com" POPUSER = "joedoe" POPPASS = "" # the number of message body lines to retrieve MAXLINES = 10 HEADERS = "From To Subject".split() # headers you're actually interested in rx_headers = re.compile('|'.join(headers), re.IGNORECASE) try: # connect to POP3 and identify user pop = poplib.POP3(POPHOST) pop.user(POPUSER) if not POPPASS or POPPASS=='=': # if no password was supplied, ask for it POPPASS = getpass.getpass("Password for %s@%s:" % (POPUSER, POPHOST)) # authenticate user pop.pass_(POPPASS) # get general information (msg_count, box_size) stat = pop.stat( ) # print some information print "Logged in as %s@%s" % (POPUSER, POPHOST) print "Status: %d message(s), %d bytes" % stat bye = 0 count_del = 0 for n in range(stat[0]): msgnum = n+1 # retrieve headers response, lines, bytes = pop.top(msgnum, MAXLINES) # print message info and headers you're interested in print "Message %d (%d bytes)" % (msgnum, bytes) print "-" * 30 print "\n".join(filter(rx_headers.match, lines)) print "-" * 30 # input loop while 1: k = raw_input("(d=delete, s=skip, v=view, q=quit) What?") k = k[:1].lower( ) if k == 'd': # Mark message for deletion k = raw_input("Delete message %d? (y/n)" % msgnum) if k in "yY": pop.dele(msgnum) print "Message %d marked for deletion" % msgnum count_del += 1 break elif k == 's': print "Message %d left on server" % msgnum break elif k == 'v': print "-" * 30 print "\n".join(lines) print "-" * 30 elif k == 'q': bye = 1 break # done ... if bye: print "Bye" break # summary print "Deleting %d message(s) in mailbox %s@%s" % ( count_del, POPUSER, POPHOST) # close operations and disconnect from server print "Closing POP3 session" pop.quit( ) except poplib.error_proto, detail: # possible error print "POP3 Protocol Error:", detail
![]() |
Similar Threads
- How to view Mail attachments (JSP)
- cant send receive mail OE (Windows NT / 2000 / XP)
- Can't Find 10.2 Jaguar Mail Setting (Mac Software)
- Dynamically Update Your Web Pages Via E-Mail (Search Engine Optimization)
- Outlook not receiving new mail (Windows NT / 2000 / XP)
- Looking for mail checker (Windows Software)
- Can't get mail past my Firewall (Windows NT / 2000 / XP)
- Receive Windows Messenger Messages and Alerts on your Mobile Device (Windows tips 'n' tweaks)
Other Threads in the Python Forum
- Previous Thread: Printing
- Next Thread: simple code to find a word in any page
Views: 4244 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






