Skip to content

Instantly share code, notes, and snippets.

@MonsieurV
Last active May 3, 2019 10:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MonsieurV/c66be0485ac4505f340d35d1b29408f9 to your computer and use it in GitHub Desktop.
Save MonsieurV/c66be0485ac4505f340d35d1b29408f9 to your computer and use it in GitHub Desktop.
This script simply mass delete mails from a mailbox through a POP3 access. May be useful when you want to clear an Inbox of spams & all.
"""
This script simply mass delete mails from a mailbox
through a POP3 access.
May be useful when you want to clear an Inbox of spams & all.
** CAUTION ** After you have selected the number of messages to delete and pressed
Enter, it really does begin to delete the emails in a permanent way. (Without passing by a trash folder)
Note: the removal is actual when the script close the POP3 connection
with the QUIT command (if you provider correctly implements the POP3 protocol).
Written by Yoan Tournade <yoan@ytotech.com>
"""
import poplib
POP_SERVER_URL = 'pop.empire.org'
POP_SERVER_PORT = 995
POP_USER = 'dark.vader@empire.org'
POP_PASSWORD = 'I hate you!'
popClient = poplib.POP3_SSL(POP_SERVER_URL, port=995)
popClient.set_debuglevel(1)
print(popClient.user(POP_USER))
print(popClient.pass_(POP_PASSWORD))
try:
mailCount = popClient.stat()[0]
print('There are {} mails in the inbox'.format(mailCount))
numberToDelete = int(input('How many do you want to delete? '))
print(numberToDelete)
# print(popClient.list()[1])
for i in range(1, numberToDelete):
popClient.dele(i)
print('{} DELE commands passed'.format(numberToDelete))
finally:
print('QUIT-ing')
popClient.quit()
print("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment