Senario : A user has sent an email by mistake to a group to which the email was originally not intended to.
The following script will identify the email id from zimbra mysql and delete it
Note: the script should be run as zimbra user
#!/bin/bash
# This script will delete emails from user mail box using subject
#
# File should contain the user email address from which the mail has to be deleted. One email address per line
#
# Usage ./deletemail.sh {filename}
#
# SCRIPT SHOULD BE RUN AS ZIMBRA USER
#
FILENAME=$1
count=0
#READING THE MAIL ADDRESS FROM FILE LINE BY LINE
while read mailid
do
#Subject of the email
subject="Work From Home Policy"
#getting the mboxstore id to search for the email in mysql
mboxid=$(zmprov getMailboxInfo $mailid | grep mailboxId | awk {'print $2'}|awk '{ print substr( $0, length($0) - 1, length($0) ) }')
echo Searching $mailid for message
# GETTING THE MESSAGE ID FROM MYSQL
msgid=$(/opt/zimbra/bin/mysql mboxgroup"$mboxid" -e "select id from mail_item where mailbox_id='$mboxid' and subject like '%$subject%'" | awk {'print $1'} | grep -v "id")
echo $msgid
echo Removing the message $msgid from $mailid
# DELETING THE MESSAGE FROM THE MAILBOX
/opt/zimbra/bin/zmmailbox -z -m $mailid dm $msgid
echo Done.
done < $FILENAME
Thank you for sharing this information. I find this information is easy to understand and very useful. Thumbs up!
ReplyDeleteMelbourne App Developer
Thank you for sharing this information. I find this information is easy to understand and very useful. Thumbs up!
ReplyDeleteMelbourne App Developer
how can i narrow down search by adding date?
ReplyDelete