The spf_installer Script

Valid for versions 82 through the latest version

Version:

82

Last modified: February 29, 2024


Overview

The /usr/local/cpanel/bin/spf_installer script allows you to add an SPF record to all of a user’s domains’ zone files from the command line. For more information about SPF records, read our Email Deliverability in cPanel documentation.

Note:
  • The /usr/local/cpanel/scripts/enable_spf_dkim_globally script allows you to enable SPF and DKIM for accounts that exist on the server, and to create the appropriate DNS records for their domains. For more information, read our The Enable SPF DKIM Globally Script documentation.
  • If the user requires full control over a domain’s SPF record, use UAPI’s EmailAuth::install_spf_records function instead of this script.

Run the script

To run this script on the command line, use the following format:

/usr/local/cpanel/bin/spf_installer username policy complete overwrite preserve

Options

Use the following options with this script:

Options Description Example
user The username to whose domains you wish to assign SPF records. cpaneluser
policy A comma-delimited list of SPF records that you wish to assign to the user’s domains. v=spf1 +a +mx +ip4:192.0.2.0/24,-ip4:203.0.113.5,+ip6:2001:db8:1a34::/64
is_complete Whether the SPF key is a complete SPF entry (ends with -all).
  • A value of 1 indicates that the policy option’s value is a complete SPF record.
  • A value of 0 indicates that the policy option’s value is not a complete SPF record.
Important:
This option is required when you use the overwrite and preserve options.
1
overwrite Whether to overwrite the existing domains’ and subdomains’ SPF records with the value of the policy option.
  • A value of 1 indicates that you wish to overwrite the user’s current SPF records.
  • A value of 0 indicates that you do not wish to overwrite the user’s current SPF records.
Important:
This option is required when you use the preserve option.
Warning:
When you run the /usr/local/cpanel/bin/spf_installer script, it inspects the zone file for the domain and records the first SPF record found. This is usually the main domain. If other subdomains have an identical SPF record, the script replaces those as well.
1
preserve Whether to add the new set of keys to the existing records.
  • A value of 1 indicates that you wish to append the policy option’s value to the user’s current SPF records.
  • A value of 0 indicates that you wish to replace the user’s current SPF record with the policy option’s value.
0
--help Displays the help text for this script. /usr/local/cpanel/bin/spf_installer --help

Success and failure

If the function does not succeed, you will receive the following error message:

Failed to set up SPF for this user.

If the function succeeds, you will not receive confirmation from the command line. To confirm that the function succeeded, navigate to cPanel’s Email Deliverability in cPanel interface (cPanel » Home » Email » Email Deliverability) for each domain that the user owns.

Additional Documentation