Skip to content

Instantly share code, notes, and snippets.

@yongkiagustinus
Created April 9, 2017 15:49
Show Gist options
  • Save yongkiagustinus/b4eb71bf439c87e7e70706a458dadbbf to your computer and use it in GitHub Desktop.
Save yongkiagustinus/b4eb71bf439c87e7e70706a458dadbbf to your computer and use it in GitHub Desktop.
Bash script to setup email for all cPanel accounts in WHM
#! /bin/sh
# Get all domains as array
# You can change /etc/trueuserdomains to /etc/userdomains if you want to include the sub domain
domains=(`cat /etc/trueuserdomains | cut -d: -f1`)
echo "Found ${#domains[@]} domains"
echo -e "\n"
for (( i=0; i<${#domains[*]}; i=i+1 ))
do
# Domain variable is ${domains[$i]}
# Create email account
# Change EMAILUSER to your choice
# Change EMAILPASSWORD to your password
# Change QUOTA to your mailbox quota in MB (Numeric please)
/scripts/addpop EMAILUSER@${domains[$i]} EMAILPASSWORD QUOTA
# Uncomment this script if you want to setup email forwarding
# This script will automatically append a line on the domain alias file
# echo "EMAILUSER@${domains[$i]}: FORWARDTO@MAIL.COM" >> ../etc/valiases/${domains[$i]}
echo ">>>>> DONE"
echo -e "\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment