Sieve Script at Connection Stage does not work

Your question

Maybe I am misunderstanding a thing.
I created a System Sieve script called connect_filter.
The contents Is like:
require [“variables”, “reject”];

if string “${env.remote_ip}” [“1.2.3.4”, “1.2.3.5”]
reject "Your IP has been blacklisted!;
stop;

I activated the script and put it at Session → Connection Stage as ‘connect_filter’

But when testing with my own remote ip nothing gets rejected. What am I doing wrong? Have I forgotten anything?

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

Two problems in your script will keep it from ever running as intended:

  1. Missing curly braces around the if block. Stalwart’s Sieve parser (like standard Sieve, RFC 5228) requires the action(s) after a test to be wrapped in { }, not just indented:
require ["variables", "reject"];

if string "${env.remote_ip}" ["1.2.3.4", "1.2.3.5"] {
    reject "Your IP has been blacklisted!";
    stop;
}
  1. Unterminated string. reject "Your IP has been blacklisted!; is missing the closing double quote before the semicolon, so the whole script fails to compile.

A script with a compile error will simply not run (and Stalwart won’t reject anything), so this is almost certainly why your test connections pass through untouched. Save the corrected script, re-activate it, and check whether the WebUI’s sieve script editor/validator flags any remaining errors before testing again.

Reference example from the docs:

require ["variables", "reject"];

if string "${env.remote_ip}" "192.0.2.88" {
    reject "Connection from this IP is not accepted.";
}

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Thanks for clarification