默认情况下,当您在 postfixadmin 中创建邮箱时,会为每个邮箱创建一个文件夹。 通过 postfixadmin 删除邮箱时,只会删除用户,即 访问被终止,但包含所有信件的邮箱文件夹仍然存在。 如果我们使用相同的登录创建邮箱,数据将保持不变,就好像我们没有删除邮箱一样。 在本教程中,我们将设置在 PostfixAdmin 中删除邮箱文件夹时自动删除它们。
您还可以订购现成的 VPS 邮件服务器,您可以在此处查看有关如何配置的更多信息:
让我们打开配置文件:
/usr/share/nginx/html/postfixadmin/config.inc.php
$CONF['mailbox_postdeletion_script']='sudo -u vmail /usr/local/bin/postfixadmin-mailbox-postdeletion.sh';
让我们创建一个脚本文件来删除邮箱文件夹:
#touch /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
#!/bin/sh
Example script for removing a Maildir from a Courier-IMAP virtual mail
hierarchy.
The script looks at arguments 1 and 2, assuming that they
indicate username and domain, respectively.
The script will not actually delete the maildir. I moves it
to a special directory which may once in a while be cleaned up
by the system administrator.
This script should be run as the user which owns the maildirs. If
the script is actually run by the apache user (e.g. through PHP),
then you could use "sudo" to grant apache the rights to run
this script as the relevant user.
Assume this script has been saved as
/usr/local/bin/postfixadmin-mailbox-postdeletion.sh and has been
made executable. Now, an example /etc/sudoers line:
apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
The line states that the apache user may run the script as the
user "courier" without providing a password.
Change this to where you keep your virtual mail users' maildirs.
basedir=/home/mail
Change this to where you would like deleted maildirs to reside.
trashbase=/var/spool/deleted-maildirs if [ ! -e "$trashbase" ]; then echo "trashbase '$trashbase' does not exist; bailing out."
exit 1
fi if [
echo $1 | fgrep '..'
]; thenecho "First argument contained a double-dot sequence; bailing out." exit 1
fi
if [ `echo $2 | fgrep '..'` ]; thenecho "First argument contained a double-dot sequence; bailing out."
exit 1fi
#subdir=`echo "$1" | sed 's/@.*//'`subdir=`echo "$1"`
maildir="${basedir}/$2/${subdir}" trashdir="${trashbase}/$2/`date +%F_%T`_${subdir}" parent=`dirname "$trashdir"` if [ ! -d "$parent" ]; then if [ -e "$parent" ]; then echo "Strainge - directory '$parent' exists, but is not a directory." echo "Bailing out." exit 1else
mkdir -p "$parent" if [ $? -ne 0 ]; thenecho "mkdir -p '$parent' returned non-zero; bailing out."
exit 1
fi
fi
fi
if [ ! -e "$maildir" ]; then
echo "maildir '$maildir' does not exist; nothing to do."
exit 1
fi
if [ -e "$trashdir" ]; then
echo "trashdir '$trashdir' already exists; bailing out."
exit 1
fi
Move or delete (Move enebled by Default)
mv $maildir $trashdir #rm -rf $maildir
exit $?
创建一个文件夹来存储已删除的邮箱
mkdir /var/spool/deleted-maildirs
对于此文件夹,您可以配置清理频率,此选项可以避免邮箱被意外删除或一段时间后可能需要数据时丢失。
现在我们需要授予 vmail 用户运行脚本的权限 /etc/sudoers
# User privilege specification
root ALL=(ALL:ALL) ALL
www-data ALL=(vmail) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh
现在邮箱文件夹在删除时移动到单独的文件夹 /var/spool/deleted-maildirs:
mv $maildir $trashdir
rm -rf $maildir
准备好。