doveadm expunge for vpopmail and custom bash Script

#!/bin/bash
# MySQL details

HOST="localhost";
USER="vpopmail";
PWD="vpopmailpasswod";

# Output sql to a file that we want to run
echo "USE vpopmail; select concat(pw_name,'@',pw_domain) as username from vpopmail;" > /tmp/query.sql;

# Run the query and get the results
results=`mysql -h $HOST -u $USER -p$PWD -N < /tmp/query.sql`;

# Loop through each row
for row in $results
do
/usr/local/dovecot/bin/doveadm expunge mailbox Trash -u $row savedbefore 30d
done

Alternative method for via cronjob in CyberPanel

#!/bin/bash
# MySQL details

HOST=”localhost”;
USER=”user_db”;
DBASE=”name_db”;
PWD=”password_db”;

# Output sql to a file that we want to run
echo “USE $DBASE; SELECT email FROM e_users LIMIT 50;” > /tmp/query.sql;

# Run the query and get the results
results=`mysql -h $HOST -u $USER -p$PWD -N < /tmp/query.sql`;

# Loop through each row
for email in $results
do
echo “doveadm expunge -u $email mailbox INBOX.* SENTBEFORE 60d”;
doveadm expunge -u $email mailbox INBOX SENTBEFORE 60d
doveadm expunge -u $email mailbox INBOX.* SENTBEFORE 30d
done

Katen Doe

Katen Doe

Hello, I’m a content writer who is fascinated by content fashion, celebrity and lifestyle. She helps clients bring the right content to the right people.

Press ESC to close