#! /usr/bin/env python
import poplib
M = poplib.POP3_SSL("mail.example.com", 995)
M.user("user@example.com")
M.pass_("password")
for i in range(M.stat()[0], 0, -1):
M.dele(i)
M.quit()
To prompt for the password rather than storing it in the script, change ("password")
to (getpass.getpass())
and add import getpass
.
Sources & Additional Examples:
Sean Vinsick's comment on Using Telnet to Delete Mass Amounts of E-mail
poplib documentation: "On most servers deletions are not actually performed until QUIT (the major exception is Eudora QPOP, which deliberately violates the RFCs by doing pending deletes on any disconnect)."
/nix | Aug 04, 2020