In this article, we will discuss about how to add SPF records and DKIM keys in cPanel using CLI.
SPF (Sender Policy Framework) tells the email receiver that the incoming email is authenticated and not a fraud from the email address. It is a security mechanism of communication between DNS servers. DKIM (Domain Key Identification Mail) uses an encrypted signature to verify the email sender. In short, it is a mechanism for email authentication. When you set up DKIM, the recipient’s DNS can check who the email is from and guarantee the No Fraud situation.
Prerequisite :
- cPanel dedicated server or cloud server
- SSH root access
Login into the server with root access using SSH.
To add DKIM Keys for a Single User, use following command:
# /usr/local/cpanel/bin/dkim_keys_install [USERNAME]
Replace “[USERNAME]” with the account’s username.
To add DKIM Keys for all users, use following command:
# for user in `ls /var/cpanel/users`; do /usr/local/cpanel/bin/dkim_keys_install $user; done
To add SPF records for a single user, use following command:
# /usr/local/cpanel/bin/spf_installer [USERNAME]
Replace “[USERNAME]” with the account’s username.
To add SPF records for a all users, use following command:
# for user in `ls /var/cpanel/users`; do /usr/local/cpanel/bin/spf_installer $user; done
Setup server to create DKIM and SPF records on new account creation
# vi /scripts/postwwwacct
Add the following at the end of the file:
print “\nInstalling DKIM / SPF Records for $name …”;
system(“/usr/local/cpanel/bin/dkim_keys_install $name”);
system(“/usr/local/cpanel/bin/spf_installer $name”);
Shell script to add DKIM and SPF records for all users:
#!/bin/bash
for user in `ls /var/cpanel/users`
do
echo “Installing SPF Record for $user…”;
/usr/local/cpanel/bin/spf_installer $user;
echo “Installing DKIM Record for $user…”;
/usr/local/cpanel/bin/dkim_keys_install $user;
done
In this article, we have covered how our support engineer add SPF records and DKIM keys in cPanel using CLI.
[Need assistance to fix this error or install tools? We’ll help you.]