Thank you for add email account script!
Script for delete email:
Code:
#!/bin/bash
# by alien.ru@mail.ru from by calocen@gmail.com (ispcp_add_email.sh)
# ver.: 1.0
# 25/11/2010
# remove email account in a control panel structure with default config
# parameters:
# 1: email_account@domain.tld where (aliases not deleted)
# 2: [rebuild]: if true, then do a rebuild of rqst-orders
DEBUG="true"
# syntax control
if [ $# -lt 1 ] ; then
echo -e "\n\nSyntax: "
echo -e "\t $0 <name@domain.tld>"
exit 01
fi
cEmail=$1
[ -z $2 ] && bRebuild="false"
[ ! -z $2 ] && bRebuild="true"
$DEBUG && echo $bRebuild
cAcc=`echo $cEmail | cut -f1 -d"@"`
cDom=`echo $cEmail | cut -f2 -d"@"`
# check if domain exists and get domain Id
nDomID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT domain_id FROM domain WHERE domain_name='$cDom';")
if [ -z $nDomID ]
then
echo -e "\n\n $cDom not exists, please add it before add email accounts"
exit 02
fi
# Check if email accounts exists
nMailID=$(mysql ispcp -ss -u ispcp_mails -pMYPASSWORD -n -e "SELECT mail_id FROM mail_users WHERE domain_id='$nDomID' AND mail_acc='$cAcc';")
$DEBUG && echo -e "nDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
if [ -z $nMailID ]
then
echo -e "\n\nE-Mail account is not exists"
echo -e "\nnDomID:$nDomID\tcDom:$cDom\tcAcc:$cAcc"
exit 03
fi
# remove email record in mail_users table
cSql="DELETE FROM mail_users WHERE mail_id='$nMailID' LIMIT 1;"
$DEBUG && echo -e "$cSql"
mysql ispcp -u ispcp_mails -pMYPASSWORD -e "$cSql"
if [ "$?" -ne "0" ] ; then exit 1 ; fi
# rebuild virtual aliases
/usr/sbin/postmap /etc/postfix/ispcp
# rebuild mail accounts if set rebuild parameter
$bRebuild && /var/www/ispcp/engine/ispcp-rqst-mngr
rm -R /var/mail/virtual/$cDom/$cAcc
Script not deleted mailboxes in /etc/postfix/ispcp/* and /var/www/ispcp/postfix/*. Please help!