Exim: email limiting per day for a cpanel domain

Following section will give the details how you can set up this on exim.


cp /etc/exim.pl /etc/exim_limit.pl

2 change the following section of code in exim_limit.pl:

if ($maxmails > 0) {
my $nummailsinhour = readbacktohour(“/usr/local/apache/domlogs/$domain-smtpbytes_log”);
my $nummailsinday = readbacktodate(“/usr/local/apache/domlogs/$domain-smtpbytes_log”);
if ($nummailsinhour > 100) {
die “Domain $domain has exceeded the max emails per hour. Message discarded.\n”;
if ($nummailsinday > $maxmails) {
die “Domain $domain has exceeded the max emails per day. Message discarded.\n”;

3 change the following line in exim_limit.pl:

sub readbacktodate {


sub readbacktohour {

4 Add the following code after that in the same exim_limit.pl:
I mean after completion of subroutine readbacktohour

sub readbacktodate {
my($filename) = @_;
my($filepos) = 0;
my $now = time();
my $onedayago = ($now – (24*60*60));
my($hitcount) = 0;
= stat($filename);

$filepos = ($size – 4096);
while($filepos >= -4096) {
if ($filepos 0) {
$buf =~ /([^\n]+\n)/;
$filepos += length($1);
$buf = substr($buf,length($1));
my @BUF = split(/\n/, $buf);
foreach (reverse @BUF) {
my($ttime,$tbytes) = split(/ /);
if ($ttime > $onedayago) {

$filepos -= 4096;
if ($filepos > Server Configuration >> Tweak Settings, in the Mail section, the line ‘The maximum each domain can send out per hour’ is no longer a limit per hour but per day. That mean if you change these settings here it will only affect the maximum emails per day. We’ve hardly limited the number of emails per hour to 100 through the code “nummailsinhour > 100”

5 Go to Exim Configuration Editor, and switch to Advance Mode,
Then search for perl_startup

change the code corresponding to that code to

do ‘/etc/exim_limit.pl’

perl_startup = do ‘/etc/exim_limit.pl’

Save it up and Exim will restart automatically with the new changes.

Good luck!