spareknet.org
Customized CPanel Solutions / Server Administration

Home
Maximum E-mails Per Hour Bug Published on January 9th, 2008 Last Modified on: September 8th, 2008

Somewhere around build 18112 of cPanel a new Maximum E-mail per Hour feature was added to cPanel. Whereas the old method you were allowed to set a maximum e-mail per hour setting for all accounts in the Tweak Settings section of the WHM, you could also raise individual account limits by adding values to /var/cpanel/maxemails. The old method used /usr/local/apache/domlogs/domain.com-smtpbytes_log to track just how many messages had been sent out for that domain. I’m still not really sure what was so wrong with this method, but for whatever that reason might be, the cPanel developers decided to change this.

The new feature still gets you the option of setting a server-wide default maximum e-mail per hour setting. You can also raise individual limits on an account-by-account basis by modifying the file /var/cpanel/maxemails. But with the new system you have to run the script /scripts/build_maxemails_config after making modifications. This in turn creates a file in the /var/cpanel/maxemailsperdomain directory with the account name containing the new limit for this domain. Tracking is done through a series of perl subroutines in the /etc/exim.pl.local file and a tracking file in the /var/cpanel/maxemailstracker directory.

Somewhere in the development of this new system a variable name was mistyped and this caused a lot of problems. Accounts were only being allowed to send the default, server-wide, number of e-mails per hour regardless of whether or not that account had an overwrite in the /var/cpanel/maxemails file or /var/cpanel/maxemailsperdomain directory.

To fix this problem, one needs to examine the /etc/exim.pl.local file, specifically the getmaxemailsperhour subroutine.

/etc/exim.pl.local (Line 337-351)
sub getmaxemailsperhour {
     my $domain = shift;
     open( my $max_fh, ‘<‘, ‘/var/cpanel/maxemailsperhour’ );
     my $maxmails = int readline($max_fh);
     close($max_fh);
     if ($maxemails != 0) {
           if (-e ‘/var/cpanel/maxemailsperdomain/’ . $domain) {
               open( my $max_fh, ‘<‘, ‘/var/cpanel/maxemailsperdomain/’ . $domain );
               $maxmails = int readline($max_fh);
               close($max_fh);
           }
     }
     return $maxmails;
}

Notice how on line 340, the variable name is $maxmails.

my $maxmails = int readline($max_fh);

And on line 343 the variable being checked is $maxemails.

if ($maxemails != 0) {

This is where the problem is happening. The extra e in the $maxemails variable on line 343 should not be there. This variable should be $maxmails. The entire subroutine should be changed to look like:

sub getmaxemailsperhour {
     my $domain = shift;
     open( my $max_fh, ‘<‘, ‘/var/cpanel/maxemailsperhour’ );
     my $maxmails = int readline($max_fh);
     close($max_fh);
     if ($maxmails != 0) {
           if (-e ‘/var/cpanel/maxemailsperdomain/’ . $domain) {
               open( my $max_fh, ‘<‘, ‘/var/cpanel/maxemailsperdomain/’ . $domain );
               $maxmails = int readline($max_fh);
               close($max_fh);
           }
     }
     return $maxmails;
}

Changing this value will allow those accounts that have a different maximum e-mail setting to use that value instead of the server-wide default.

With the old /etc/exim.pl.local file, $maxemails was never defined and was therefore never not equal to 0, so that entire code segment was not being run. This meant that regardless of whether or not an account had its own maximum e-mail per hour setting, it was never being looked up.

Alternatively to fix this problem you can download a patch that I developed to resolve this issue. To apply the patch, just log into your server via shell and type:

patch -p0 < eximmaxperhour.patch

After you apply the patch, any account that you have set a personal value for sending out mail per hour for will be able to use that value. You need to be sure that you run /scripts/build_maxemails_config after you modify the /var/cpanel/maxemails file.

Downloads

eximmaxperhour.patch — Patch to modify exim.pl.local to fix maximum mail per hour setting for customized values.