Bulk Delete Email Accounts using SSH Command cPanel/WHM

I want to delete Mass Email Accounts from My cPanel/Whm Server

I want to delete Mass Email Accounts from My cPanel/Whm Server

Example Email list is.

smtp1234@mydomain1.com
smtp2345@mydomain2.com
smpt4567@mydomain3.com

for deleting these emails I have followed this doc Delete email address · cPanel & WHM Developer Portal

uapi --user={My Domain Username} Email delete_pop email='{full email address that need to be deleted}'

this command works perfectly to delete 1 email account and it’s all data.

However, I want to make it loop

Just like

uapi --user={ALL cPanel USER'S USERNAMES ON MY SERVER} Email delete_pop email='{ALL EMAIL STARTING WITH WORD *smtp* @ ALL DOMAINS}'

Hope to have a valued reply.

Is this the list? is “smtp1234@mydomain1.com” also username? If both are true, then:

list="smtp1234@mydomain1.com smtp2345@mydomain2.com smpt4567@mydomain3.com"
for email in $list
do
     echo uapi --user="${email}" Email delete_pop email="${email}"
done

thanks alot for your kind reply , i just have an email list that i want remove

smtpfox-uhmoc@toparmybadges.com
smtpfox-fkq81@baralasports.com
and so on…

as well i tried the below commands but unfortunately no luck.

Single delete: usr/local/cpanel/cpanel-email delpop {email address i want to delete} NOT WORKED

Bulk Delete: for i in `cat userslist.txt`; do /usr/local/cpanel/scripts/delpop $i ;done NOT WORKED

cat emaillist.txt | while read EMAIL;do uapi --user={cpanel username} Email delete_pop email=$EMAIL;done

Now just problem left in cPanel usernames fetching

that I have tried with 2 methods

  1. extract the domain name from the email address that I have already list. then cPanel account name based on that extracted domain … but no luck

I have tried regex to get the domain name.
URI="pw@example.com"
echo $URI | sed -e ‘(?<=@)[^.]+(?=.)’

and after getting the domain name
/scripts/whoowns $DOMAIN NAMe

it helps me to get exactly what I want. but unfortunately, I’m not being able to join these methods in my above loop command. please try to help with this

Hi,

Your problem is not clear. Can you post your sample input file? Also how do youg et $DOMAIN and NAMe? What are those? Then only we can help

/scripts/whoowns $DOMAIN NAMe

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki