Implementing Quota Checking for Email Sending with KumoMTA

Hi, I need to solve a use case using KumoMTA. I’m trying to implement quota checking in my email sending. For example: I have a plan of 5 emails, but when I try to send an email to more than 5 recipients in a single email using BCC and CC, I need to block this email thread because I have a 5-email plan, but my email thread has more than 5 emails. How can I resolve this use case?

Hey there @winsome-lion, thanks for posting. Please read the “Troubleshooting” and “How to Ask for Help” buttons below. If you would like a 1:1 support session from the KumoMTA team, details are at the “Book a Support Session” button below.

The simplest option is to limit the number of recipients that are allowed per SMTP transaction by setting max_recipients_per_message to 1

Then your smtp_server_message_received - KumoMTA Docs event handler only ever has to deal with a single recipient at a time.

An alternative option is to perform your quota check in the smtp_server_rcpt_to - KumoMTA Docs event.
assuming that the metadata in the object: connectionmeta - KumoMTA Docs object is sufficient for your specific case.

Thanks a lot for the response, @free-spirited-yorksh

Hi, @free-spirited-yorksh @faithful-ostrich @yearning-hyena i looked into this solution you provided, and i’m still facing some issues. Since event handler deals with a single recipient at a time, i check the quota each time and consider the processed mail as a success one, but when the quota is exceeded and i try to terminate the remaining messages, the entire mail thread is killed and processed mails are also rejected. How can i solve this issue? Either i need to sent the processed messages and reject only the remaining ones or i need to get the count of recipients in the mail thread. I cant limit the recipients of the mail

Perhaps limit the injection to one per connection?

I am thinking you need to shift the rejection to mail from. Update the count as they are queued, but check against the count in the next mail from event.