How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
-
ingenetic98
- Posts: 26
- Joined: Thu Feb 16, 2023 1:03 am
How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
Hi all ,
Did anyone know How to delete all email on specific account mailbox , from specific sender address from cli ?
ex : i have one user : userA@myzimbrauser.com
and i want to delete all email from specific sender address (ex: jerry@mycustomer.com) on userA@myzimbrauser.com mailbox ?
and , is it possible to delete all email from specific sender address ( (ex: jerry@mycustomer.com) ) from all mailbox my zimbra users account ? ( because we have one system here, which sending notification by email everyday to a lot of user here ).
and i thought that email will be same as junk mails. beside not everyone will read that notification, because they already access to that system everyday .
for now , start from December , 01 -2023 to prevent that notification email sending to my zimbra user, i adding sender address from that notification email system to blacklist zimbra .
by the end of this year i have to create zimbra backup , it will be suffering (takes too long) to backup , because there are so many emails from that notification system ( very very lot of emails ).
Please advice.
Best regards,
Did anyone know How to delete all email on specific account mailbox , from specific sender address from cli ?
ex : i have one user : userA@myzimbrauser.com
and i want to delete all email from specific sender address (ex: jerry@mycustomer.com) on userA@myzimbrauser.com mailbox ?
and , is it possible to delete all email from specific sender address ( (ex: jerry@mycustomer.com) ) from all mailbox my zimbra users account ? ( because we have one system here, which sending notification by email everyday to a lot of user here ).
and i thought that email will be same as junk mails. beside not everyone will read that notification, because they already access to that system everyday .
for now , start from December , 01 -2023 to prevent that notification email sending to my zimbra user, i adding sender address from that notification email system to blacklist zimbra .
by the end of this year i have to create zimbra backup , it will be suffering (takes too long) to backup , because there are so many emails from that notification system ( very very lot of emails ).
Please advice.
Best regards,
Re: How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
find all messages in a mailbox from a particular sender
You delete using the msgId so ideally if you want to build a list of msgId's, something like...
Let's just delete the last one (271), and check it again - you'd do this.
So if you did...
That should be enough to get you going, always test first.
kb
Code: Select all
[zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net"
num: 4, more: false
Id Type From Subject Date
---- ---- -------------------- -------------------------------------------------- --------------
1. 274 mess user3 asdfasdf 11/29/23 00:43
2. 273 mess user3 asdfasdf 11/28/23 21:26
3. 272 mess user3 test 11/28/23 21:20
4. 271 mess user3 Here It Is 11/28/23 21:17Code: Select all
[zimbra@zimbra-training-1c ~]$zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net" | egrep mess| awk '{print $2}' > /tmp/user1_deletesCode: Select all
[zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net dm 271
[zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net"
num: 3, more: false
Id Type From Subject Date
---- ---- -------------------- -------------------------------------------------- --------------
1. 274 mess user3 asdfasdf 11/29/23 00:43
2. 273 mess user3 asdfasdf 11/28/23 21:26
3. 272 mess user3 test 11/28/23 21:20
Code: Select all
[zimbra@zimbra-training-1c ~]$ for i in `cat /tmp/user1_deletes`; do zmmailbox -z -m user1@ztraining.net dm $i ;donekb
Re: How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
Here again, firing up zmmailbox many times to delete many messages will be *very* slow (several seconds JDK invocation time for each message).karl.b wrote: ↑Fri Dec 08, 2023 10:00 pmCode: Select all
[zimbra@zimbra-training-1c ~]$ for i in `cat /tmp/user1_deletes`; do zmmailbox -z -m user1@ztraining.net dm $i ;done
Better pipe a bunch of "dm" commands into a single zmmailbox instance:
Code: Select all
for i in `...`
do echo dm $i
done | zmmailbox -z -m ...-
slacker1337
- Posts: 47
- Joined: Fri Aug 30, 2019 8:54 am
Re: How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
Try using this method:
Code: Select all
$ echo "sm user1@ztraining.net" > /tmp/user1_deletes_batch
$ for i in `cat /tmp/user1_deletes`; do echo "dm $i"; done >> /tmp/user1_deletes_batch
$ zmprov -f /tmp/user1_deletes_batch
-
ingenetic98
- Posts: 26
- Joined: Thu Feb 16, 2023 1:03 am
Re: How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
hi , i already try this one :karl.b wrote: ↑Fri Dec 08, 2023 10:00 pm find all messages in a mailbox from a particular sender
You delete using the msgId so ideally if you want to build a list of msgId's, something like...Code: Select all
[zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net" num: 4, more: false Id Type From Subject Date ---- ---- -------------------- -------------------------------------------------- -------------- 1. 274 mess user3 asdfasdf 11/29/23 00:43 2. 273 mess user3 asdfasdf 11/28/23 21:26 3. 272 mess user3 test 11/28/23 21:20 4. 271 mess user3 Here It Is 11/28/23 21:17
Let's just delete the last one (271), and check it again - you'd do this.Code: Select all
[zimbra@zimbra-training-1c ~]$zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net" | egrep mess| awk '{print $2}' > /tmp/user1_deletes
So if you did...Code: Select all
[zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net dm 271 [zimbra@zimbra-training-1c ~]$ zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net" num: 3, more: false Id Type From Subject Date ---- ---- -------------------- -------------------------------------------------- -------------- 1. 274 mess user3 asdfasdf 11/29/23 00:43 2. 273 mess user3 asdfasdf 11/28/23 21:26 3. 272 mess user3 test 11/28/23 21:20
That should be enough to get you going, always test first.Code: Select all
[zimbra@zimbra-training-1c ~]$ for i in `cat /tmp/user1_deletes`; do zmmailbox -z -m user1@ztraining.net dm $i ;done
kb
zmmailbox -z -m user1@ztraining.net s -t message "From:user3@ztraining.net"
and delete the message id with command :
zmmailbox -z -m user1@ztraining.net dm 271
with this command i have to delete mannualy one by one on each mailbox account ?
is there any fastest way to delete all email from specific sender address ? for 1 mailbox account or all mailbox account , because almost all user (at least 200 users) on my zimbra server receive this notification mail.
how to delete all mails, in all accounts or each account, received from a specific sender,
for ex : userA@myzimbra.com , has 500 emails notification mail from specific sender on his mailbox ( inbox , junk folder or specific folder )
and i want to delete it all 500 emails from user A mailbox . is that possible ?
Please advice.
-
slacker1337
- Posts: 47
- Joined: Fri Aug 30, 2019 8:54 am
Re: How to delete all email on specific account mailbox or all account , from specific sender address from cli ?
Not the best one, but it should work. Unfortunately I haven't found a way without looping through all the mailboxes to find correct message Id(s). But at the end the final batch file is executed just once.
Inspired by: https://wiki.zimbra.com/wiki/King0770-N ... on-Subject
Please use with caution!!!
Inspired by: https://wiki.zimbra.com/wiki/King0770-N ... on-Subject
Please use with caution!!!
Code: Select all
#!/bin/bash
[[ -z "$1" ]] && { echo "Usage: $0 user@domain.com"; exit 0; }
batch=${0}.batch
printf "\nSearching for messages with specified From address across all mailboxes..\n\n"
for user in $(/opt/zimbra/bin/zmprov -l gaa); do
printf "$user ..."
msgids=$(/opt/zimbra/bin/zmmailbox -z -m $user s -l 999 -t message "From:$1" | egrep -v "Id|---|^$" | awk '{ if (NR!=1) {print $2}}' | paste -sd ',')
if [ ! -z $msgids ]; then
echo "sm $user dm $msgids" >> $batch
printf " Found Id(s) $msgids\n"
else
printf " Not found\n"
fi
done
if [ -s $batch ]; then
printf "\nAll messages found will be deleted.. "
read -p "Continue? (Y/n): " confirm
if [[ "$confirm" =~ ^[Yy]+([eE][sS])?$ ]]; then
/opt/zimbra/bin/zmprov -f $batch
rm -f $batch
printf "\nDone\n\n"
else
printf "\nInterrupted, exiting..\n\n"
fi
else
printf "\nNothing has been found, exiting..\n\n"
fi

