FrankHock
FrankHock

Reputation: 64

Limit the number of emails a user can send out per day

I'm looking for a suggestion on limiting the number of emails a user can send himself each day in a rails app I'm working on.

The site is a lead generating site so each user would have access to a list of leads. The user then can review the lead information. If he wants to follow up on the lead he can email himself the lead including the contact information that otherwise is hidden.

However I'd like to limit how many times he can email himself. Any suggestions?

Upvotes: 0

Views: 245

Answers (1)

Matthew Walton
Matthew Walton

Reputation: 9969

The obvious approach is to keep a record of every email send the user does in a simple table which wouldn't need anything more than user ID and a timestamp in it. Then each time they want to send another one, pull all their send records with timestamps within the last twenty-four hours (or since start of business this morning, or wherever the 'day' boundary is for your situation), count them and see if they're allowed to send another one.

I don't think it really needs to be any more complicated than that. You could of course clean up the table from time to time if it has entries >24 hours old in it. Along those lines, another solution is to just store a count of 'emails sent', and reset all of those on the dot of midnight each day. That requires something else floating around to do the reset of course - maybe your database server can do that kind of thing (or a cron job could), but it seems a bit too detached from the rest of the code for my liking.

Upvotes: 1

Related Questions