Skip to main content


This section contains a collection of example Sieve scripts that can be used as a starting point for your own scripts.


The following script implements a simple greylisting filter using an SQL database:

script = "greylist"

greylist = '''
require ["variables", "vnd.stalwart.expressions", "envelope", "reject"];

set "triplet" "${env.remote_ip}.${envelope.from}.${}";

if eval "!query("SELECT 1 FROM greylist WHERE addr = ? LIMIT 1", [triplet])" {
eval "query("INSERT INTO greylist (addr) VALUES (?)", [triplet])";
reject "422 4.2.2 Greylisted, please try again in a few moments.";

Domain blocklisting

The following script implements a domain blocklisting filter during the EHLO phase:

script = "is-blocked"

is-blocked = '''
require ["variables", "extlists", "reject"];

if string :list "${env.helo_domain}" "sql/blocked-domains" {
reject "551 5.1.1 Your domain '${env.helo_domain}' has been blocklisted.";

blocked-domains = "SELECT 1 FROM blocked_domains WHERE domain=? LIMIT 1"

Message modification

The following example modifies the incoming message by replacing the content of all HTML parts with their uppercase version and adding a custom header to each part:

script = "modify-message"

modify-message = '''
require ["envelope", "variables", "replace", "mime", "foreverypart", "editheader", "extracttext"];

if envelope :domain :is "to" "" {
set "counter" "a";
foreverypart {
if header :mime :contenttype "content-type" "text/html" {
extracttext :upper "text_content";
replace "${text_content}";
set :length "part_num" "${counter}";
addheader :last "X-Part-Number" "${part_num}";
set "counter" "${counter}a";