Enabling email authentication (SPF and DKIM) for all existing accounts – cPanel/WHM

Is it possible? A back-end option to enable SPF and DKIM for already created cPanel accounts?

In cPanel, backend scripts are available to enable SPF and DKIM for all accounts that are already created without enabling email authentications, SPF and DKIM. We have already discussed “How to enable SPF and DKIM automatically for all newly creating accounts?“. That’s simple, right!

[Shrotcut to script]

Enabling this features in the DNS will increase the reputation of all emails sent out from that account (domain). SPF stands for “Sender Policy Framework”, it’s a TXT record to the domain DNS. DKIM stands for “Domain Keys Identified Mail”, DKIM is an authentication protocol that is used by email receivers to determine original ownership of that email. In a DKIM enabled domain, an encrypted digital signature will add to all emails sent out from that domain which will help to identify the originality of that email.

cPanel script to enable SPF via commandline:

Syntax

# /usr/local/cpanel/bin/spf_installer $username

Where, $username is the cPanel user name.

cPanel script to enable DKIM via commandline:

Syntax

#  /usr/local/cpanel/bin/dkim_keys_install $username

Replace $username with the actual cPanel username.

The above commands will help you to enable email authentications for single cPanel users. If you have hundreds of accounts and you want to enable SPF and DKIM for all accounts, please follow the simple for loop.

Here we can get the cPanel usernames from “/var/cpanel/users”. Then give that to installations scripts. Please see the sample script below:

Script

for username in `ls -A /var/cpanel/users` ; do
       /usr/local/cpanel/bin/dkim_keys_install $username  &&
       /usr/local/cpanel/bin/spf_installer $username ; done

That’s it! wait for a while, it’ll set all.

Also read:

1, How to run Python scripts with cPanel?
2, cPanel account (domain) migration steps from backend
3, How to check cpanel license details?

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

3 thoughts on “Enabling email authentication (SPF and DKIM) for all existing accounts – cPanel/WHM

  1. hello how do i run the srcipt in the command line, please tell me step by step i have 1,200 and above accounts in my server i want to apply SPF and DKIM at on click thanks

    1. If it is a cPanel server, you can use the same script via shell:

      for username in `ls -A /var/cpanel/users` ; do /usr/local/cpanel/bin/dkim_keys_install $username  && /usr/local/cpanel/bin/spf_installer $username ; done
      

Leave a Reply

Your email address will not be published. Required fields are marked *