The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Daily Mail Sending Limits

Discussion in 'E-mail Discussions' started by asterisk, Apr 4, 2006.

  1. asterisk

    asterisk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    61
    Likes Received:
    0
    Trophy Points:
    6
    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?
     
  2. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
  3. asterisk

    asterisk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    61
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  4. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    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.
     
  5. asterisk

    asterisk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    61
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  6. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    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.
     
  7. asterisk

    asterisk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    61
    Likes Received:
    0
    Trophy Points:
    6
    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
     
    #7 asterisk, Apr 5, 2006
    Last edited: Apr 5, 2006
  8. sawbuck

    sawbuck Well-Known Member

    Joined:
    Jan 18, 2004
    Messages:
    1,367
    Likes Received:
    5
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Nice work! :)
     
  9. AndyReed

    AndyReed Well-Known Member
    PartnerNOC

    Joined:
    May 29, 2004
    Messages:
    2,222
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    Minneapolis, MN
    That's a very good piece of work :) CHEERS
     
Loading...

Share This Page