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 firstname.lastname@example.org
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:
Let’s assume that you need to change an existing contact email: email@example.com and to replace it for all the cPanel accounts with firstname.lastname@example.org.
While you are in your terminal, connected to your server, browse to /var/cpanel/users/:
And do a grep for “email@example.com” in each file:
grep -irl "firstname.lastname@example.org"
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 email@example.com with firstname.lastname@example.org. The command line is:
for i in $(cat users.txt); do sed -i 'email@example.comfirstname.lastname@example.org/g' $i; done
The same steps will need to be applied to do the bulk change of the email stored in /home/user/.contactemail.