Limit the number of emails sent per user

Remco00

Verified User
Joined
Feb 22, 2006
Messages
283
I know it is possible to limit the amount of mails users can sent per day (see this item). However I want to change limits per user. So one user can sent eg 100 mails per day and another user can sent 250 mail per day. Is this possible and what changes should I make in the exim.pl file to make this work? I also took a look at this thread but I don't know if that is the best sollution. Anyone else already figured this out?
 
Last edited:
Thanks for your reply fwpeter. I have looked at that post but I'm wondering how to modify the exim.pl exactly so that individual limits can be assigned per user.
 
You can also change the code around however you want (if you know how).. for example, you could edit the "sub check_limits" function (below uid_exempt) and have it read in /etc/virtual/limit.1234 where 1234 is the clients UID number, thus giving you per user limits, etc.. (you'd need a file for each user).. or have it read in /etc/virtual/limits, then check if limits.1234 exists, and overwrite the $email_limit variable if it does.. thus giving you a default (limits) and override (limits.1234) if you want.
 
Ok, with some help of this post I modified the part in exim.pl into this:

Code:
sub check_limits
{
	my $count = 0;

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

	my $userlimit = "/etc/virtual/usage/${name}.limit";
	if (-e $userlimit) {
	open (LIMIT, "$userlimit");
	} else {
	open (LIMIT, "/etc/virtual/limit");
	}
	my $email_limit = int(<LIMIT> );
	close(LIMIT);

	#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");

	log_bandwidth($uid);

	return "yes"
}
 
open (LIMIT, "/etc/virtual/limit");

I was checking the code for exim.pl and was just wondering doesn't setting a limit of say 100 in /etc/virtual/limit file would only allow a person to send 100 emails ever.

Does setting say a limit of 100 applies per day? It doesn't looks to me that there is any cron process that is resetting the daily count for a user? Can we set limit per domain? I think it would be good to have this functionality in DA interface?

How about emails going out from PHP mail() function which normally sends emails using the webserver user id?

Thanks
 
Any more info on this. I just had a cleint who only sends 20 -40 emails a day reach a limit of 1000. This tells me this info is not rotating daily.
 
As I mentioned previously in my post that after reading exim.pl i found that if you just set a value in /etc/virtual/limit file then a user on the system will only be allowed to send that many emails ever from the server. There is no cron process or anything that will rotate the counters back to zero either on DAILY or WEEKLY bases. So you now either have to write your own modified exim.pl as most of the people might have done or create a shell/perl script to reset the counter for each user.
 
The /etc/virtual/limit is the daily limit per domain.
each domain can send email to reach limit after that will error.
and it's reset daily with standard installation without modification exim.pl

You can check /etc/virtual/usages for infomation
 
thanks kke for the update. Could you please guide me that which process resets the counter to 0 everyday?
 
look
nano /etc/virtual/limit
write number of sending mail per day
 
Hello,

DirectAdmin resets the files in /etc/virtual/usage/* every day... assuming you have a new version of DA that actually does it. If you're using an older version of DA, it might not be doing it. The current version of DA is 1.29.4, so make sure you're running that (or newer).

John
 
Hello,

Could you please tell at what time DA resets the counter? I have been having problems with this not reseting to zero.

Thanks,

Dec
 
I have the same problems. The counter does not reset and clients can't send email.
 
Hello,

The counter is reset with the tally.
The tally by default runs at 12:10am, just after midnight.
The script that the tally calls is:
/usr/local/directadmin/scripts/rotate_email_usage.sh
You do not need to call this script, but can if you want.

Most likely, the tally is not being run.
Use this guide to ensure it's all running:
http://help.directadmin.com/item.php?id=107

John
 
Back
Top