Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-1225

Set limits on the number of mails that can be sent from a given site in a given period

    Details

    • Type: New Feature
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 1.5
    • Fix Version/s: Unscheduled
    • Component/s: None
    • Labels:
      None

      Description

      Particularly in ASP environments, it's sometimes necessary to set limits on the number of mails sent from a site in a given time period. For example, sites might be classed into three package options: free trial (limited to 500 mails per month), basic package (limited to 1,000), full package (20,000).

      There is the CIVICRM_MAILER_BATCH_LIMIT setting, but that controls the number of mails sent out at once from the queue--not the number added to the queue in the first place.

      We need to:
      (a) designate mail quotas per time period
      (b) track number of mails sent per time period, up to quota
      (c) on new mailing, prevent queuing if it would exceed remaining quota
      (d) optimally, have option of setting quota to zero, blocked, in case e.g. of spamming detected.

      Here are some thoughts on how we might do this, please comment and correct/improve:

      1. Add two new settings to civicrm.settings.php, CIVICRM_MAILER_QUOTA_LIMIT and CIVICRM_MAILER_QUOTA_PERIOD, read into the Config object as $config->mailerQuotaLimit and $config->mailerQuotaPeriod. These set the limit (number of mails allowed) and the period, e..g, 30 days.

      2. Implement new Quota class. This is for storing, incrementing, and returning available and used quota portions.

      Properties:

      • limit – from $config->mailerQuotaLimit
      • period – from $config->mailerQuotaPeriod
      • start_date – start date of last period
      • renew_date – date at which quota will be flushed (now + (period - (now - start_date)))
      • used – total mails sent since beginning of last period
      • remaining – number of mails remaining (limit - used)

      Methods:

      • flush: set start_date to now and used to 0.
      • getUsed: return the number used (calculated from stored value)
      • getRemaining: return the number remaining (calculated dynamically by subtracting used from limit)
      • increment: increment used by 1 (unsets remaining, so it will be refreshed as needed)

      Questions:

      • How do we store a value like used?
      • what should this new class extend?

      3. Increment the Quota 'used' value with every mail successfully sent.

      Questions:

      • Where in the code do we do this?

      4. Before a mailing is queued, determine if it will potentially exceed the available quota, and, if so, cancel.

      In CRM_Mailing_BAO_Job, provide an override to function queue().

      Questions:

      • how to return notice to admin/user who queued mailing?
      • Is this the best place to override? We could do so earlier, returning a message to the user trying to schedule or dispatch a mailing: "

      5. Present feedback to user on remaining quota.

      E.g., an information message at /civicrm/mailing: "You have [remaining] messages remaining in your mail quota. The quota will be renewed to [limit] on [renew_date].

      Attached are some initial ideas toward a patch.

        Attachments

          Activity

            People

            • Assignee:
              kiran.jagtap Kiran Jagtap
              Reporter:
              nedjo Nedjo Rogers
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: