How to delete a email sent to all zimbra users

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
nishan56838
Posts: 5
Joined: Wed Jul 05, 2017 6:25 am

How to delete a email sent to all zimbra users

Post by nishan56838 »

Hi,
If mistakenly I sent a email to all users and I want to delete it from the all users since its a wrong email for something. is there anyway to delete particular subject email from all email users within my domain. I have access to email server. I found below script, but its not working. Can anyone help me on this. (https://wiki.zimbra.com/index.php?title ... he_Subject)

Code: Select all

#!/bin/bash
# rm_message.sh user@domain.com subject
if [ -z "$2" ]; then
echo "usage:  rm_message.sh user@domain.com <subject>"
exit 0
else
addr=$1
subject=$2
echo "Searching $addr  for Subject:  $subject"
for msg in `zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'`
  do
echo "Removing "$msg""
zmmailbox -z -m $1 dm $msg
done
fi
phoenix
Ambassador
Ambassador
Posts: 27278
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

Re: How to delete a email sent to all zimbra users

Post by phoenix »

nishan56838 wrote:I found below script, but its not working.
That doesn't actually tell us much, does it? What exactly isn't working? What have you tried to fix it? You should always give the exact version of Zimbra you're using by posting the full output of the following command:

Code: Select all

zmcontrol -v
You should always give a full description of the problem and the errors you see and what steps you've taken to try and fix the problem.
Regards

Bill

Rspamd: A high performance spamassassin replacement

Per ardua ad astra
nishan56838
Posts: 5
Joined: Wed Jul 05, 2017 6:25 am

Re: How to delete a email sent to all zimbra users

Post by nishan56838 »

phoenix wrote:
nishan56838 wrote:I found below script, but its not working.
That doesn't actually tell us much, does it? What exactly isn't working? What have you tried to fix it? You should always give the exact version of Zimbra you're using by posting the full output of the following command:

Code: Select all

zmcontrol -v
You should always give a full description of the problem and the errors you see and what steps you've taken to try and fix the problem.
Thank you for your reply.
version of my zimbra is Release 8.6.0_GA_1153.RHEL6_64_20141215151155 RHEL6_64 FOSS edition. This is not an issue. All I want to do is delete particular subject email from all users that they received.

As a Example: User A sent an email to DL all@domain.com and its including all of the local zimbra users. So user A wrongly sent that email and he want to recall that. In zimbra we have not recall option. so user A request his IT admin to delete that wrong email from all users.

All i want to know, is there any way to delete particular subjected email from all users at once. Did you got my point.
User avatar
JDunphy
Outstanding Member
Outstanding Member
Posts: 897
Joined: Fri Sep 12, 2014 11:18 pm
Location: Victoria, BC
ZCS/ZD Version: 9.0.0_P39 NETWORK Edition

Re: How to delete a email sent to all zimbra users

Post by JDunphy »

nishan56838 wrote:
All i want to know, is there any way to delete particular subjected email from all users at once. Did you got my point.
That script loops to find all the email in one account which is an argument you provide that matches the subject. You want it to cycle through all the users.
This command lists all the users in the system.

Code: Select all

zmprov -l gaa
You would need to update the script, and put an outer loop so that all the users are tried for the variable addr.

or you could do this from the command line:

Code: Select all

for user in `zmprov -l gaa`
do
   rm_message.sh $user subject
done
nishan56838
Posts: 5
Joined: Wed Jul 05, 2017 6:25 am

Re: How to delete a email sent to all zimbra users

Post by nishan56838 »

JDunphy wrote:
nishan56838 wrote:
All i want to know, is there any way to delete particular subjected email from all users at once. Did you got my point.
That script loops to find all the email in one account which is an argument you provide that matches the subject. You want it to cycle through all the users.
This command lists all the users in the system.

Code: Select all

zmprov -l gaa
You would need to update the script, and put an outer loop so that all the users are tried for the variable addr.

or you could do this from the command line:

Code: Select all

for user in `zmprov -l gaa`
do
   rm_message.sh $user subject
done
Thank you JDunphy. But the thing is the script that I given is not working at all. I tried with a one user account but it wont delete. Could you check the whole script and check weather its wrong or correct.

Thank you,
Nishan.
User avatar
JDunphy
Outstanding Member
Outstanding Member
Posts: 897
Joined: Fri Sep 12, 2014 11:18 pm
Location: Victoria, BC
ZCS/ZD Version: 9.0.0_P39 NETWORK Edition

Re: How to delete a email sent to all zimbra users

Post by JDunphy »

nishan56838 wrote: Thank you JDunphy. But the thing is the script that I given is not working at all. I tried with a one user account but it wont delete. Could you check the whole script and check weather its wrong or correct.
It deletes something from my account. How about you go slow to pin point where your problem is... Perhaps your search criteria?
The first part of the script is trying to get the message id.. so do this by hand. I have old Logwatch entries so that is what I am searching on.

Code: Select all

su - zimbra
zmmailbox -z -m user@example.com s -l 999 -t message "subject:Logwatch"
That would return a list of messages for that user that it matched. In my case, it returns a list of 14 messages on my test machine with their message id's. Next delete one of those messages by its id where 683109 will be replaced by what you see from the above command.

Code: Select all

zmmailbox -z -m user@example.com dm 683109
Now run the first command again and observe that the list is 1 entry shorter.
User avatar
JDunphy
Outstanding Member
Outstanding Member
Posts: 897
Joined: Fri Sep 12, 2014 11:18 pm
Location: Victoria, BC
ZCS/ZD Version: 9.0.0_P39 NETWORK Edition

Re: How to delete a email sent to all zimbra users

Post by JDunphy »

Here is a revised version that doesn't do the delete but echo's out what is happening. It is safe to run and prints the command vs executing the command.

Code: Select all

!/bin/bash
# rm_message.sh user@domain.com subject
if [ -z "$2" ]; then
echo "usage:  rm_message.sh user@domain.com <subject>"
exit 0
else
addr=$1
subject=$2
echo "Searching $addr  for Subject:  $subject"
zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"
echo "Now parsing the message id"
zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'
for msg in `zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'`
  do
  echo "Removing "$msg""
  echo zmmailbox -z -m $1 dm $msg
  done
  fi
twokeys
Posts: 41
Joined: Sat Sep 13, 2014 2:57 am

Re: How to delete a email sent to all zimbra users

Post by twokeys »

This script is dangerous as it pulls up emails containing anything you put in the subject.

You need to surround the search with brackets: "subject:(This is a bad email)"

Otherwise youll remove anything containing any of those keywords.
edisu
Advanced member
Advanced member
Posts: 71
Joined: Fri May 01, 2020 3:25 am

Re: How to delete a email sent to all zimbra users

Post by edisu »

twokeys wrote:This script is dangerous as it pulls up emails containing anything you put in the subject.

You need to surround the search with brackets: "subject:(This is a bad email)"

Otherwise youll remove anything containing any of those keywords.
Hi, where do i neet to put the brackets? Can you revise the script? Thanks
edisu
Advanced member
Advanced member
Posts: 71
Joined: Fri May 01, 2020 3:25 am

Re: How to delete a email sent to all zimbra users

Post by edisu »

JDunphy wrote:Here is a revised version that doesn't do the delete but echo's out what is happening. It is safe to run and prints the command vs executing the command.

Code: Select all

!/bin/bash
# rm_message.sh user@domain.com subject
if [ -z "$2" ]; then
echo "usage:  rm_message.sh user@domain.com <subject>"
exit 0
else
addr=$1
subject=$2
echo "Searching $addr  for Subject:  $subject"
zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"
echo "Now parsing the message id"
zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'
for msg in `zmmailbox -z -m "$addr" s -l 999 -t message "subject:$subject"|awk '{ if (NR!=1) {print}}' | grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'`
  do
  echo "Removing "$msg""
  echo zmmailbox -z -m $1 dm $msg
  done
  fi
Hi Jim,

Can you revise the script for me, cause when i run the script it also pulls up email containing anything you put in thr subject.

Is it possible to delete only the exact keyword on the subject? How can i add on the script? Thanks
Post Reply