How to delete all or some emails from a mailbox without logging in to the mailbox?

Follow

Comments

3 comments

  • Avatar
    Nathan Wilson

    Hi,

    I'm looking at running a daily job to delete all spam items older than 1 month (like Gmail does).

    Can I confirm this command will do the trick?

    for i in $(plesk bin mail -l | tr '\t' ' ' | cut -d' ' -f 3-); do doveadm expunge -u "$i" mailbox INBOX.Spam before 1m; done

    Thanks.

    0
    Comment actions Permalink
  • Avatar
    Anton Maslov

    Nathan Wilson syntax looks correct, thought we do not test any anything like this to guarantee it will work for 100%.

    p.s. I would do a small change to your command to exclude aliases as they have no separate mailbox:

    for i in $(plesk bin mail -l | grep -v Alias| tr '\t' ' ' | cut -d' ' -f 3-); do doveadm expunge -u "$i" mailbox INBOX.Spam before 1m; done
    1
    Comment actions Permalink
  • Avatar
    Stavros T

    That is a great one! thanks for that. 

    This script solves a major problem with the clients that using gmail pop3 to get their emails.
    Gmail does not grab the spams and the plesk mailboxes getting full. 

     

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request