Get Free Linux Server Security, Performance & Troubleshooting Tips

How to Add SPF and DKIM to All Domains in cPanel Servers

Question: How can I add SPF and DKIM to all domains in cPanel server? Answer: You can do it with this tyny handy script that we will show you below using the command line from the root user of your cPanel server.

SPF and Domaink Keys (DKIM) are one of the best practices you can do for your mail services, and for your users mail services to authenticate your email in the right way. This features provide information about incoming mail from your server. Email servers use this authenticated information to verify that a trusted sender sent the messages, and not a 3rd party ilegitimate user.

SPF and DKIM records help to avoid spam issues, ISPs blocking your emails, and lot of more issues related to email authentication.

Add a SPF record and DKIM on cPanel for a particular domain

The best way to do it is from the cPanel control panel of each domain.

  1. Login to cPanel.
  2. Click on ‘Email Authentication’.
  3. Click ‘Enable’ button below DKIM and below SPF.

All done, now you have a generic DKIM and SPF record for your domain name.

Add SPF and DKIM for one particular domain from the command line

Using this simple commands you can generate SPF and DKIM records, just replace ‘username’ with your real cPanel username, and that’s all.

/usr/local/cpanel/bin/dkim_keys_install username
/usr/local/cpanel/bin/spf_installer username

Add SPF and DKIM to All Domains on a cPanel Server

There is a simple way to add SPF and DKIM to all the domains inside your cPanel box. Just copy and paste this command and it will automatically add SPF records and DKIM records to all domains on the server.

cd /var/cpanel/users/
for user in * ; do /usr/local/cpanel/bin/dkim_keys_install $user && /usr/local/cpanel/bin/spf_installer $user ; done

As you see, this is a simple ‘for loop’ uses the same command we used before for both SPF and DKIM records, but the big difference is that this commands applies to all cpanel usernames inside the /var/cpanel/users/ directory.

That’s it, now you know how to Add SPF and DKIM to All Domains on your server. Do you know other ways to massive add SPF / DKIM records on cPanel servers?

Further reading:

About the Author: Esteban Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

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