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.
is there any solution if i just want to execute the script for specific hosting package?
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.
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
It contains all the info you will need.
http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/ScriptHooks
Regards,
hai there, howsa goin 😀
finally i did it the script :
http://cuap.dit.web.id/index.php/2009/08/06/tentukan-batas-pengiriman-imel-per-jam-sesuai-paket-hosting-saat-membuat-akun-hosting-baru-dari-whm/
thx for your information back there…
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?
@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,
hai…
too bad my server crashed [hard disk drive],
and all the research on my blog is gone 🙁
@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—-
I was looking for this information. Thanks for sharing.
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
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
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);
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']
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()
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.
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.
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
@Guilherme Carvalho :
you should create it first if you dont have one.
Just was searching for this automation. Thanks for posting it online.
will this update serials in DNS including cPanel clustered DNS nature? If not, what will you suggest?
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?
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
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
Note:
from 11.32 – > /usr/local/cpanel/bin/dkim_keys_install