ispCP - Board - Support
add email account script - Printable Version

+- ispCP - Board - Support (http://www.isp-control.net/forum)
+-- Forum: ispCP Omega Contributions Area (/forum-40.html)
+--- Forum: Snippets (/forum-42.html)
+--- Thread: add email account script (/thread-2073.html)



add email account script - calocen - 01-03-2008 02:59 AM

I hope this bash script will be useful for people, like me, who are migrating from another panel solutions.

To use the script download and rename it from .txt to .sh

please notify some bug.

[attachment=276]


RE: add email account script - Zothos - 01-03-2008 03:56 AM

no file XD


RE: add email account script - mafia - 05-11-2010 04:09 AM

Hello, first thanks a lot

Can I ask if this script is still
updated at this time?ispCP 1.0.5


RE: add email account script - Alien85 - 11-25-2010 01:05 PM

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!