Daily Mail Sending Limits

asterisk

Well-Known Member
Nov 11, 2005
61
0
156
Hi,

How can I set the daily mail sending limits per domain to a certain number?

I have adjusted the hourly limits via WHM but would also like an overall daily limit to cap it as well. And is there a way to set exclusions for certain domains, changing their limits to another value please?
 

asterisk

Well-Known Member
Nov 11, 2005
61
0
156
Hey,

Thanks very much for pointing to that post. It was most certainly helpful although it wasn't really what I am hoping to do.

I am interested in setting a limit on the maximum number of e-mails that can be sent in a day.

For example, I have a 500 hourly sending limit.
I would like to have a max of 3000 daily limit.

The two limits is useful so that someone may send a burst of emails within the hour of up to 500 but at the same time, the daily limit is more for mailing list users to not set some sort of batch processing to utilise the 500 hourly limit at its maximum capacity for 24 hours.

The exclusions are for the higher-end accounts where the daily limits may be set to 6000 or 9000.
 

sawbuck

Well-Known Member
Jan 18, 2004
1,365
10
168
cPanel Access Level
Root Administrator
Assumed it was only a partial answer to your question but haven't seen the config info to accomplish what you are after.
 

asterisk

Well-Known Member
Nov 11, 2005
61
0
156
I found out that this can be done in Exim 4.60 with its Rate Limiting feature but unfortunately Cpanel does not support that yet.

Has anybody around here managed to implement a daily mail sending limit on their servers?

Would really appreciate any help I can get.
 

chirpy

Well-Known Member
Verifed Vendor
Jun 15, 2002
13,437
33
473
Go on, have a guess
If you need it before v4.60 is supported (and for that you should log an enhancement bugzilla entry) then you could have a play with /etc/exim.pl where cPanel currently does just that with the hourly limits.
 

asterisk

Well-Known Member
Nov 11, 2005
61
0
156
Thanks for the helpful tip. That's a great idea indeed.

For those who may want this feature ahead of Exim 4.60's integration into Cpanel, what I did was, as root:

Code:
cp /etc/exim.pl /etc/exim_limit.pl
and changed the following section of code in exim_limit.pl:

Code:
      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 > 500) {
            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";
         }
      }
and change the following line in exim_limit.pl:

Code:
sub readbacktodate {
to:

Code:
sub readbacktohour {
and add the following code after that in the same exim_limit.pl:

Code:
sub readbacktodate {
   my($filename) = @_;
   my($buf);
   my($filepos) = 0;
   my $now = time();
   my $onedayago = ($now - (24*60*60));
   my($hitcount) = 0;
   my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
         $atime,$mtime,$ctime,$blksize,$blocks)
      = stat($filename);

   $filepos = ($size - 4096);
   open(RF,"$filename");
   seek(RF,$filepos,0);
   while($filepos >= -4096) {
      if ($filepos < 0) {
         read(RF,$buf,($filepos+4096));
      } else {
         read(RF,$buf,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) {
            $hitcount++;
         }
      }

      $filepos -= 4096;
      if ($filepos < 0) {
         seek(RF,0,0);
      } else {
         seek(RF,$filepos,0);
      }
   }

   return($hitcount);
}
After the code change, under WHM >> Server Configuration >> Tweak Settings, in the Mail section, the line 'The maximum each domain can send out per hour (0 is unlimited)' is no longer a limit per hour but per day.

Following Chirpy's helpful tip which sawbuck has kindly pointed out, one can modify daily limits for certain domains that one desires.

If one wishes to change the hourly limit, this has been hardcoded into the exim_limit.pl file in the 4th line of the 1st code box above as 500 hourly.

For the final step, go to Exim Configuration Editor, and switch to Advance Mode, adding this to the first box.

Code:
perl_startup = do '/etc/exim_limit.pl'
Save it up and Exim will restart automatically with the new changes.

Good luck!

PS In case YMMV, this is for Exim 4.52 on WHM 10.8.0 cPanel 10.8.1-R113
 
Last edited:

AndyReed

Well-Known Member
PartnerNOC
May 29, 2004
2,217
4
193
Minneapolis, MN
asterisk said:
For those who may want this feature ahead of Exim 4.60's integration into Cpanel, what I did was, as root: ...........
That's a very good piece of work :) CHEERS