Skip to content

Instantly share code, notes, and snippets.

@jeena
Created October 17, 2019 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeena/6f510fdd8f05f0b7b512e23aad8ea9a1 to your computer and use it in GitHub Desktop.
Save jeena/6f510fdd8f05f0b7b512e23aad8ea9a1 to your computer and use it in GitHub Desktop.
Delete all emails in GMail
#!/usr/bin/env python2
import gmail # from https://github.com/charlierguo/gmail
from datetime import datetime, timedelta, date
print "Logging in inte GMail ...",
g = gmail.login("foo", "test")
print "done."
d = date(2018, 10, 30)
while True:
print "Getting mails for %s ..." % d,
emails = g.inbox().mail(on=d)
print "deleting %d ..." % len(emails),
for email in emails:
email.delete()
# seems to take at least 2 seconds
# with my 1.000.000 mails it'll take over 20 days
print("done.")
d = d - timedelta(days=1)
g.logout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment