How can I empty gmail inbox from bash or sh? Can it be done using gmail POP3 server pop.gmail.com:995 or imap? I found a way to read emails via atom but it seems that it does not work via POP3 so the emails stay in the inbox.

link|improve this question
Please don't double-post: serverfault.com/questions/345654/empty-gmail-inbox-from-bash – ziesemer Jan 1 at 5:40
feedback

3 Answers

Connect to Gmail IMAP using any console IMAP client:

  • mutt:

    mutt -f "imaps://imap.gmail.com/INBOX"
    

    ShiftT.EnterdShift$

  • alpine, re-alpine

    alpine -f "{imap.gmail.com/ssl}INBOX"
    
  • heirloom-mailx, GNU mailutils

    mail -f "imaps://imap.gmail.com/INBOX"
    

    Delete all: d *q

  • Python:

    import imaplib
    im = imaplib.IMAP4_SSL("imap.gmail.com")
    im.login("user", "passwd")
    typ, data = im.search(None, 'ALL')
    for num in data[0].split():
        im.store(num, '+FLAGS', '\\Deleted')
    im.expunge()
    
link|improve this answer
feedback

you can use poplib module of python to check the mail and delete it accordingly see this for details

link|improve this answer
feedback

I guess you can do it quickly by logging in via the web. Click on the checkbox on the top of the list. This will select the first page mails. Now you will notice a link which will have a text which goes like "All xx conversations on this page are selected. Select all xxx conversations in Inbox" where xx is the number of conversations you see in the page and xxx is the number of total mails. Click on that link and then click on the bin icon (Delete). This will delete all your inbox. Follow the similar procedure for the outbox and drafts. Done!

link|improve this answer
1  
While this accomplishes the end result, Nutel is interested in doing this through bash or the terminal. – iglvzx Jan 1 at 5:58
@iglvzx Maybe this can be done in Lynx? – Daniel Beck Jan 1 at 13:52
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.