This shows you the differences between two versions of the page.
— |
pythonpopflush [2014/10/25 21:52] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | == Delete all messages from a POP3 mailbox == | ||
+ | <code python> | ||
+ | #!/usr/bin/python | ||
+ | |||
+ | import poplib | ||
+ | |||
+ | accounts = [ | ||
+ | { 'server' : 'mail.engineer.com', | ||
+ | 'user' : 'user1@engineer.com', | ||
+ | 'pass' : 'secret' | ||
+ | }, | ||
+ | { 'server' : 'mail.python.com', | ||
+ | 'user' : 'user@python.com', | ||
+ | 'pass' : 'Secret' | ||
+ | } | ||
+ | ] | ||
+ | |||
+ | #print str(accounts) | ||
+ | for ac in accounts: | ||
+ | print 'Handle %s' % ac['server'] | ||
+ | pop = poplib.POP3(ac['server']) | ||
+ | pop.user(ac['user']) | ||
+ | pop.pass_(ac['pass']) | ||
+ | (count, sz) = pop.stat() | ||
+ | for i in range(1,count+1): | ||
+ | pop.dele(i) | ||
+ | print "%s: Delete %d" % (ac['server'],i) | ||
+ | pop.quit() | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ---- | ||
+ | |||
+ | * [[pythoninfo|Back to Python]] | ||