Remove queued mail from a sender domain?

My Lua skills are not top notch and I could not find a full answer in the help. If I want to remove mail from a sender domain which I don’t want to send anymore.. Would this piece of code then nuke all that mail silently? I do have mail with different subdomains.. Is there a way to regex match… there probably is, but I did not find it yet in the lua tutorials I quickly skimmed.

kumo.on('requeue_message', function(msg)
  local queue = msg:get_queue_name()
  local mydomain = msg:from_header().domain
  -- domain should be an array
  if mydomain == "news.domainname.com" and msg:num_attempts() >= 1 then
    -- move to nill queue and thus nuking it?
    msg:set_meta('queue', 'nill')
  end
end)

That looks sane theoretically but requeue_message only works on currently trans failed messages. It will not do anything to messages that are at rest in the queue.

We have an admin bounce function that might be more useful

You can invoke that with kcli so it can be done from an external app

Use the —domain switch to do the same thing your script does above.

It will natively remain active for 5 minutes to catch any new injections. You can extend that with the —duration switch.

note that the bounce command works on the recipient domain, not the sender domain

You can’t msg:set_meta('queue', 'null') after reception, because there isn’t actually a null queue, it is a special label used at reception time to skip inserting into any queues.

What I would suggest is to define a rebind_message event:

kumo.on('rebind_message', function(msg, data)
  if some_condition then
    kumo.reject(500, "don't send this any more")
  end
end)

then run:

$ kcli rebind --everything --trigger-rebind-event

that will cause every message from every queue to be passed through the rebind_message event. The kumo.reject will cause matching messages to bounce.

re: regex, lua has built in matching functions, but the syntax is… unusual. We have our own compile - KumoMTA Docs that uses the more familiar pcre style regex syntax

Thanks Wez… I will go for the rebind_message solution as I need to ditch mail from a certain sender

^^^ Ohh that is much better :slightly_smiling_face:

Was that sender in its own tenant?

no, it was in a shared warmup tenant… but crap got injected.

nothing to warmup :frowning_face_with_open_mouth:

Ugh.

I’d try to have a shared pool and individual tenants.

that is actually something to think about

I did do this as suggested but I am not seeing bounces (in the logs) on the domains I want to clear. So probably my condition is not right. Is this about right?

kumo.on('rebind_message', function(msg, data)
  local mydomain = msg:from_header().domain
  -- domain should be an array
  if mydomain == "newsletter.domain.com" then
    kumo.reject(500, "don't send this any more")
  end
end)

Then I did:
kcli rebind --everything --trigger-rebind-event --reason "Need to cleanup some domains"