email limit send mail

sander815

Verified User
Joined
Jul 29, 2003
Messages
474
is it posible to set a maximum per user for sending email through smtp, f.i. 250 emails / day or so?
 
We'll be looking at something like that when we update exim and include the new exim.conf (jlaman's).. and integrated spamassasin controls. No eta though.

John
 
Hi im check the DirectAdmin Knowledgebase and works, but i want know if i can setup custom number of emails to some accounts, like:

admin - 2000 dayli mails
xxxx- 200 dayli mails
xxxx - 500 dayli mails
 
I don't think it can be done that way. Perhaps someone else will respond.

Jeff
 
It is possible, but will require some adjustments. Please note that the following code is untested and usage is at your own risk

Create a copy of your exim.pl and open it:

Code:
cp /etc/exim.pl /etc/exim.pl.bak
nano /etc/exim.conf

Replace

Code:
sub check_limits
{
        my $count = 0;
        open (LIMIT, "/etc/virtual/limit");
        my $email_limit = int(<LIMIT>);
        close(LIMIT);

        #find the curent user
        $uid = find_uid();

        #log_str("Found uid: $uid\n");

        if (uid_exempt($uid)) { return "yes"; }

        my $name="";
        if ($email_limit > 0)
        {
                #check this users limit
                if (($name = getpwuid($uid)))
                {
                        $count = (stat("/etc/virtual/usage/$name"))[7];
                        if ($count > $email_limit)
                        {
                                die("You ($name) have reach your daily email limit of $email_limit emails\n");
                        }

                        open(USAGE, ">>/etc/virtual/usage/$name");
                        print USAGE "1";
                        close(USAGE);
                        chmod (0660, "/etc/virtual/usage/$name");
                }
        }

        my $sender_address = Exim::expand_string('$sender_address');
        my $mid = Exim::expand_string('$message_id');

        log_bandwidth($uid,"type=email&email=$sender_address&method=outgoing&id=$mid");

        return "yes"
}

With:

Code:
sub check_limits
{
        my $count = 0;

        #find the curent user
        $uid = find_uid();
        $name = getpwuid($uid)

        open (LIMIT, "/etc/virtual/limit");
        my $email_limit = int(<LIMIT>);
        close(LIMIT);

        #log_str("Found uid: $uid\n");

        open (USERLIMIT, "/etc/virtual/$name.limit");
        my $user_limit = int(<USERLIMIT>);
        close(USERLIMIT);     

        if (uid_exempt($uid)) { return "yes"; }  

        my $name="";
        if ($email_limit > 0 or $user_limit > 0)
        {
                #check this users limit
                $count = (stat("/etc/virtual/usage/$name"))[7];
               if ($count > $email_limit)
               {
		die("You ($name) have reach your daily email limit of $email_limit emails\n");
               }
               if ($count > $user_limit)
               {
               	die("You ($name) have reach your daily email limit of $email_limit emails\n");
               }

               open(USAGE, ">>/etc/virtual/usage/$name");
               print USAGE "1";
               close(USAGE);
               chmod (0660, "/etc/virtual/usage/$name");
        }

        my $sender_address = Exim::expand_string('$sender_address');
        my $mid = Exim::expand_string('$message_id');

        log_bandwidth($uid,"type=email&email=$sender_address&method=outgoing&id=$mid");

        return "yes"
}

Create a limitation:

Code:
echo 300 > /etc/virtual/username.limit

And restart Exim:

Code:
/sbin/service exim restart

You can revert your changing as well:

Code:
rm -f /etc/exim.pl
mv /etc/exim.pl.bak /etc/exim.pl
/sbin/service exim restart
 
Note that exim.pl is occasionally updated by DirectAdmin staff; when they do that you'll have to update your customized file yourself.

Jeff
 
Good point.

I thought you could already set limits on a per user basis, but it seemed I was wrong. So perhaps there is someone else who can confirm this already is a feature.
 
Hello, i active the limit send per day, but the problem is in one user (mine) show me more than 111111 and im limit to 1000, and other thing, im just setup a new account im only sent 1 email but showme 11, so its working this system?
 
Last edited:
is it posible to set a maximum per user for sending email through smtp, f.i. 250 emails / day or so?

I do something like this in exim.conf:

warn ratelimit = 1000 / 12h / per_rcpt / strict
delay = 30s
log_message = Sender $sender_address rate $sender_rate / $sender_rate_period excedes limit delayed 30 seconds

This will throttle any IP that trys to send to over 1000 recipients in a 12 hour period. Not sure if that is something like you want or not. More info at exim.org on ratelimit. We also enforce another ratelimit is Squirrelmail.

Matthew
 
Hello, i active the limit send per day, but the problem is in one user (mine) show me more than 111111 and im limit to 1000, and other thing, im just setup a new account im only sent 1 email but showme 11, so its working this system?

Just remember in the usage files 111111 is 6 emails. 11 is 2 emails.
 
Code:
warn ratelimit = 1000 / 12h / per_rcpt / strict
        delay = 30s
        log_message = Sender $sender_address rate $sender_rate / $sender_rate_period excedes limit delayed 30 seconds
I can see using this to avoid mail servers sending spam, but I'm not sure it will help you control your own users. Either they send email from your server (you can't block your own server from sending email) or they send it from their home or office connection on which the IP# will change.

Jeff
 
Interesting point... should I perhaps consider adding this code to the SpamBlocker exim.conf file? Community input welcomed.

Jeff
 
@hci:

Does your code also limit 127.0.0.1 (localhost)? If so, then won't it limit mailing lists run on the server?

Jeff
 
Does your code also limit 127.0.0.1 (localhost)? If so, then won't it limit mailing lists run on the server?

I don't beleive so but it does limit squirrelmail. It can be setup to ignore 127.0.0.1 to avoid this. I have had spammers break into squirrelmail accounts though so I also added the limit senders plugin to squirrelmail and removed all other webmail clients.

Mattew
 
I'd like to see some additional input. Someone please update this thread by Monday morning if no-one else has, so I'll see it and act on it.

Thanks.

Jeff
 
Back
Top