In this tutorial, you will learn how to bulk update/change Contact Email for accounts in WHM. This is useful when you have a reseller and want to change the default email address on all of the accounts with a different email address.

 

If you’re not feeling comfortable using the command line interface, we recommend you to do it manually in WHM.

 

To do so,  navigate to Account Information >> List Accounts area. Here you will see all the accounts listed. Then click on the ‘+’ sign in front of the username then change the contact email for the account(s) that you want.

 

In case you prefer doing it for a single or few accounts from the command line, you can use:

cpapi2 --user=user CustInfo savecontactinfo email=zach@safei.com

 

To Bulk Update/Change Contact Email for accounts in WHM

We’ll assume that you have root access to your server. The contact email address for each cPanel account is stored in two different files: 

  • /var/cpanel/users/user 
  • /home/user/.contactemail

 

Let’s assume that you need to change an existing contact email: zach@safei.com and to replace it for all the cPanel accounts with jordan@rootadminz.com.

 

While you are in your terminal, connected to your server, browse to /var/cpanel/users/:

cd /var/cpanel/users/

 

And do a grep for “john@smith.com” in each file:

grep -irl "zach@safei.com"

 

It will start listing the files that have a match for the search term. E.g:

./user1
./user2
./user3

 

Now you will have to create a text file in /var/cpanel/users/ e.g: users.txt and to add the results of your search using grep command.

 

Next, we’ll use sed to replace all the instances matching john@smith.com with smith@john.com. The command line is:

for i in $(cat users.txt); do sed -i 's/john@smith.com/smith@john.com/g' $i; done

 

The same steps will need to be applied to do the bulk change of the email stored in /home/user/.contactemail.

 

Was this answer helpful? 0 Users Found This Useful (1 Votes)