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

Follow

Comments

7 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 (Edited )

    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 since 4weeks; done
    1
    Comment actions Permalink
  • Avatar
    Stavros Tsalikoglou

    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
  • Avatar
    Jason Millis

    Anton Maslov & Nathan Wilson, the `1m` in your snippets would remove all mails older than 1 minute.

    From dovecot's documentation, supported time units are:

    Available time units are: weeks (abbr: w), days (abbr: d), hours (abbr: h), mins (abbr: m) and secs (abbr: s).

    I've just made that mistake, thankfully it was only on my emails in the trash folders.

    I'd suggest you use 31d to cover the longest months.

    0
    Comment actions Permalink
  • Avatar
    Alejandro Garcia de Alba

    Hi, how can this be done for Plesk in Windows?

    0
    Comment actions Permalink
  • Avatar
    Tobias Sorensson

    i edited the script that plesk provides here

    #!/bin/bash
    for mailbox in $(plesk bin mail -l | grep -v Alias| tr '\t' ' ' | cut -d' ' -f 3-); do
        doveadm expunge -u $mailbox mailbox 'INBOX.Trash' since 4weeks
        doveadm expunge -u $mailbox mailbox 'INBOX.Spam' since 2weeks
    done

    i hope that his helps someone. this script will delete all mail in trash that is older than 4 weeks and it will also remove all mail in spam folder that is older than 2 weeks.

     

    0
    Comment actions Permalink
  • Avatar
    Steve Yates

    The shown syntax mailbox '*' did not work for me, I had to use mailbox INBOX instead.  mailbox INBOX.'*' as shown worked for other/sub folders.

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request