I need help to find the right command to delete all mail in a specific user's inbox coming from specific domains (spam mail from @qq.com or @sohu.com"...)


Here's how I'd do :

cd to the user's mailbox

cd /var/vmail/domain.tld/user/

Look visually for all the mail coming from qq.com

grep --color=always "^From:.*qq.com" -r .

Adjust the grep filter if there are non qq mail included in the results until you only have mail from qq.com, then

for email in $(grep --color=no "^From:.*qq.com" -l -r .); do echo $email --; rm -rf $email; done;

This will delete all the e-mails for a specific maildir.

You can of course apply to all mailboxes, but it's dangereous.

  • Thank you for your answer. Can you help me what command to delete all email of user by year condition. Example: all mail in 2016 year. Sorry if you find troublesome
    – hungudgm
    Jul 23 '19 at 2:58

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