How To Add DomainKeys and SPF Records on CPanel Servers

on April 27 | in Hosting / Servers, Linux, Programming / Scripting | by | with 27 Comments

This how to describe how to add domainkeys and SPF (Sender Policy Framework) records on CPanel Servers. Whenever you create a domain on CPanel server using WHM, it wont add domainkeys and SPF records for particular domains. To add domainkeys and SPF records please use following steps.

We consider here we have a domain sohailriaz.com with cpanel username sohailri

Please note on CPanel servers most of the work is done using cpanel username which then reflect setting on particular domains. If you have several domains / sub domains under one username, it will add domainkeys and SPF records for all domains / subdomains.

Execute the following command on your CPanel server using root.

1 DomainKeys

1.1 Add DomainKeys for single user

/usr/local/cpanel/bin/domain_keys_installer sohailri

where sohailri is a username

1.2 Add DomainKeys for all CPanel users.

If you wish to add DomainKeys for all Cpanel users on your server, execute following command.

ls /var/cpanel/users | while read a; do
/usr/local/cpanel/bin/domain_keys_installer $a
done

2 SPF (Sender Policy Framework)

2.1 Add SPF for single account.

/usr/local/cpanel/bin/spf_installer sohailri

2.2 Add SPF for all Cpanel accounts.

If you want to add SPF records for all cpanel accounts exist on your server then use the following command.

ls /var/cpanel/users | while read a; do
/usr/local/cpanel/bin/spf_installer $a
done

3 Enable DomainKeys and SPF for every new CPanel account.

If you want to add DomainKeys and SPF for every new account created on Cpanel, then do the following.

vi /scripts/postwwwacct

postwwwacct is a file which execute after wwwacct (used to create account), paste following lines in the file

#!/usr/bin/perl

my %OPTS = @ARGV;
$ENV{USER} = “$OPTS{‘user’}”;
system q(/usr/local/cpanel/bin/domain_keys_installer $USER);
system q(/usr/local/cpanel/bin/spf_installer $USER);

Happy Mailing 🙂

If you have any question / suggestion please comment.

Pin It

related posts

27 Responses to How To Add DomainKeys and SPF Records on CPanel Servers

  1. is there any solution if i just want to execute the script for specific hosting package?

  2. admin says:

    The scripts which i used is developed by CPanel and they uses users as a input to install SPF or Domainkey for the specific user.
    You can see the /var/cpanel/users directory and check for any user for your specific hosting package. You should see some unique in that user file for that hosting package.
    Then you have to developed your own script which first take out the users name which are in any specific hosting package and then you can run above commands on those users to generate SPF and DomainKeys.

  3. admin said :
    Then you have to developed your own script which first take out the users name which are in any specific hosting package and then you can run above commands on those users to generate SPF and DomainKeys.

    thats exactly what im asked before 😀

    the main idea is, i want to execute other script [not spf-ing] while creating new hosting account. and the script only apply for specific hosting plan [package].

    1. is there any clue on what file i have to attach my script?
    2. what keyword i should use for comparison?

    thanks

  4. A Osama says:

    cat /var/cpanel/users | while read a; do /usr/local/cpanel/bin/domain_keys_installer $a; done

    The above command does not work with me:
    /var/cpanel/users: is a directory

    Any ideas?

  5. @Osama: Sorry for mistake the command is like this
    ls /var/cpanel/users | while read a; do /usr/local/cpanel/bin/domain_keys_installer $a; done
    ————-
    I have fixed in the blog too. Please use the command as above and go with post again, it will execute fine.
    ————–
    Regards,

  6. hai…

    too bad my server crashed [hard disk drive],
    and all the research on my blog is gone 🙁

  7. A Osama says:

    @Sohail: thanks for the correction. I had already ran it by using *for* instead of *while*.
    —–
    for user in `ls /var/cpanel/users`; do /usr/local/cpanel/bin/domain_keys_installer $user; done
    —-

  8. I was looking for this information. Thanks for sharing.

  9. Mark says:

    Great guide. Thank you for writing it, but the code provided to place in postwwwacct for adding domain keys and spf records for all newly created accounts did not work for me in CENTOS 5.5 x86_64

    The code below did work:

    #!/usr/bin/perl

    print “\nStarting install of Domainkeys\n”;
    my %OPTS = @ARGV;
    my $user = $OPTS{‘user’};
    system(“/usr/local/cpanel/bin/domain_keys_installer”,$user);
    system(“/usr/local/cpanel/bin/spf_installer”,$user);
    print “\nDone with install of Domainkeys\n”;exit;

    Also, after inserting the code you can test the syntax using this code:

    perl -c postwwwacct

  10. adding spf and do the max mail sending hourly limit after creating an account [automatically] :
    http://dit.web.id/2011/02/21/cpanel-1128x-tentukan-limitasi-pengiriman-email-saat-pembuatan-akun-hosting/

    @mark :
    Also, after inserting the code you can test the syntax using this code perl -c postwwwacct << thx

  11. Chris says:

    I added Mark’s suggested code to the postwwwacct file using vi, but upon testing with the perl -c command I got some compilation errors, plus there was already a lot of stuff in the file. Any suggestions?
    ————————————————————
    root@server [~]# vi /scripts/postwwwacct
    iptaglist = parsedipDOC.getElementsByTagName(‘ip’)
    iplist =[]

    q = 0
    while q /dev/null 2>&1″, shell=True)
    output = proc.communicate()

    #!/usr/bin/perl

    my %OPTS = @ARGV;
    $ENV{USER} = .$OPTS{.user.}.;
    system q(/usr/local/cpanel/bin/domain_keys_installer $USER);
    system q(/usr/local/cpanel/bin/spf_installer $USER);

  12. Chris says:

    Top Half of postwwwacct file
    ———————————————–
    root@server [~]# vi /scripts/postwwwacct
    iptaglist = parsedipDOC.getElementsByTagName(‘ip’)
    iplist =[]

    q = 0
    while q < len(iptaglist):
    iplist.append(str(iptaglist[q].childNodes[0].toxml()))
    q = q + 1

    f = open('/var/cpanel/userdata/' + newuser + '/main')
    ydata = yaml.load(f)
    f.close()
    sublist = ydata['sub_domains']

  13. Chris says:

    middle
    ——————————
    addondict = ydata[‘addon_domains’]
    parkedlist = ydata[‘parked_domains’]
    domainlist = ydata[‘main_domain’]
    domain = domainlist
    docroot, yip, alias = createvhosts.getvars(domain)
    if yip == iplist[0]:
    createvhosts.writeconfshared(newuser, domain, docroot, yip, alias)
    else:
    createvhosts.writeconfded(newuser, domain, docroot, yip, alias)

    proc = subprocess.Popen(“/etc/init.d/nginx restart > /dev/null 2>&1”, shell=True)
    output = proc.communicate()

  14. Chris says:

    end
    ——————-

    #!/usr/bin/perl

    my %OPTS = @ARGV;
    $ENV{USER} = .$OPTS{.user.}.;
    system q(/usr/local/cpanel/bin/domain_keys_installer $USER);
    system q(/usr/local/cpanel/bin/spf_installer $USER);
    ——————————–
    I have also tried it taking out the #!/usr/bin/perl part. Still getting the following errors

    root@server [~]# perl -c /scripts/postwwwacct
    Semicolon seems to be missing at /scripts/postwwwacct line 6.
    Semicolon seems to be missing at /scripts/postwwwacct line 7.
    syntax error at /scripts/postwwwacct line 7, near “v ”
    /scripts/postwwwacct had compilation errors.

  15. Chris says:

    Okay one problem I noticed for all others purposes..

    the ” and ‘ were replaced with .’s upon copy and pasting the code so watch to make sure the code doesn’t change. Still need help with the compilation error.

  16. […] 4. Set up DomainKeys Identified Mail (DKIM) on your email server. This is similar to SPF records in that it is a way for major isps to identify the mail coming from your domain. This system is used by Gmail, Yahoo, SBCGlobal, British Telecom, Rogers Cable, Rocket Mail so if you want to get your mail to these isps you should set up DomainKeys. Here are some instructions on how to set up Domain keys on your server. If you are using a cpanel server with ssh root access here are some ssh commands you can use to put domain keys on all domains on your server in less than… […]

  17. […] 4. Set up DomainKeys Identified Mail (DKIM) on your email server. This is similar to SPF records in that it is a way for major isps to identify the mail coming from your domain. This system is used by Gmail, Yahoo, SBCGlobal, British Telecom, Rogers Cable, Rocket Mail so if you want to get your mail to these isps you should set up DomainKeys. Here are some instructions on how to set up Domain keys on your server. If you are using a cpanel server with ssh root access here are some ssh commands you can use to put domain keys on all domains on your server in less than… […]

  18. Guilherme Carvalho says:

    i´m looking to add the script to ALL new domains, but i don´t have the /scripts/postwwwacct, i only have the /scripts/wwwacct and /scripts/wwwacct2

    How can i do that? i´m using cPanel 11.28.87

    Thanks

  19. @Guilherme Carvalho :
    you should create it first if you dont have one.

  20. Soma says:

    Just was searching for this automation. Thanks for posting it online.

  21. ATUL KHACHANE says:

    will this update serials in DNS including cPanel clustered DNS nature? If not, what will you suggest?

  22. Khaleal says:

    Just was searching for this automation. Thanks for posting it online.
    By the way, will adding SPF ensure that messages are not sent to JunkMail?

  23. David says:

    Thanks for the great doc! Very helpful. One change:

    The cPanel command for domain keys has changed from:

    /usr/local/cpanel/bin/domain_keys_installer

    to

    /usr/local/cpanel/bin/dkim_keys_install

  24. Rajesh says:

    Hi,
    Is there a way to sign outgoing emails with domainkeys in cpanel. My emails header always shows “DKIM: pass, SPF: pass, DMARC: pass. **domainkey signature: neutral (no signature)

    Thanks

  25. Luka says:

    Note:
    from 11.32 – > /usr/local/cpanel/bin/dkim_keys_install

Leave a Reply

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

« »