Current time: 05-04-2024, 11:33 AM Hello There, Guest! (LoginRegister)


Post Reply 
add email account script
Author Message
Alien85 Offline
Newbie
*

Posts: 8
Joined: Nov 2010
Reputation: 0
Post: #4
RE: add email account script
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!
(This post was last modified: 11-25-2010 06:30 PM by Alien85.)
11-25-2010 01:05 PM
Find all posts by this user Quote this message in a reply
Post Reply 


Messages In This Thread
add email account script - calocen - 01-03-2008, 02:59 AM
RE: add email account script - Zothos - 01-03-2008, 03:56 AM
RE: add email account script - mafia - 05-11-2010, 04:09 AM
RE: add email account script - Alien85 - 11-25-2010 01:05 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)