Difference between revisions of "Sieve"

(Created page with "This article is a short how-to on using Sieve Filters on Zimbra. Sieve is a powerful scripting language for filtering incoming email messages. While Zimbra supports user set i...")
 
 
Line 1: Line 1:
 +
 +
== Zimbra Sieve admin Sieve filter rules ==
 +
 +
 
This article is a short how-to on using Sieve Filters on Zimbra. Sieve is a powerful scripting language for filtering incoming email messages. While Zimbra supports user set incoming email filters, the Sieve filters are meant to be set-up and installed by administrators.
 
This article is a short how-to on using Sieve Filters on Zimbra. Sieve is a powerful scripting language for filtering incoming email messages. While Zimbra supports user set incoming email filters, the Sieve filters are meant to be set-up and installed by administrators.
  

Latest revision as of 08:37, 21 March 2022

Zimbra Sieve admin Sieve filter rules

This article is a short how-to on using Sieve Filters on Zimbra. Sieve is a powerful scripting language for filtering incoming email messages. While Zimbra supports user set incoming email filters, the Sieve filters are meant to be set-up and installed by administrators.

Sieve via the Admin Console UI

You can set-up Sieve filter rules for Class of Service (CoS) and Domains in the Admin Console web-ui. The settings can be found in the Advanced section: CoS→Advanced→Sieve. and Domains→Advanced→Sieve.

For more information on the actual Sieve syntax read the section below.

Sieve via the command line using zmprov

First you want to allow the adding of email headers, which is useful for debugging your filter scripts:

  zmprov mc default zimbraSieveEditHeaderEnabled TRUE

Then create a text file with your Sieve script. In this example we use /tmp/myfilters:

require ["fileinto", "reject", "tag", "flag", "editheader"];

# add an external domain header to all email not coming from our own domains
if allof(
  not address :domain :is ["from"] ["example.org", "lists.example.org", "otherdomain.nl"]
)
{
  addheader "X-External-Domain" "Warning come from external domain";
}

# restrict anyone that uses example.com to mail to a domain that is not example.nl, but allow mailing to info2@example.com. To notify the sender in case the mail is rejected. Instead of `reject`, you can use `discard`. Discard will not tell the sender the email was not delivered
if allof(
  address :domain :is ["from"] ["example.com"],
  not address :domain :is ["to"] ["example.nl"],
  not address :is ["cc", "to"] ["info2@example.com"]
)
{
  reject "sorry gautam does not allow you to email";
  stop;
}

Some more examples:

require ["fileinto", "reject", "tag", "flag", "editheader"];
# filter based on any header containing barry, put it in the barry folder
if anyof (header :contains "from" "barry" )
{
    addheader "X-MyBarry-Header" "itsdabom";
    fileinto "barry";
    stop;
}

#Filter email based on a subject
if header :contains "Subject" [
  "Logwatch"
  ]
{
    fileinto "Logwatch";
    stop;
}

#Filter based on a custom header, that indicates email was forwarded via a rule in outlook.com
if header :contains "X-MS-Exchange-Inbox-Rules-Loop" [
  "user@hotmail.com"
  ]
{
    fileinto "forwarded-from-outlook";
    stop;
}

# If you do not like sendgrid, you can move it to Junk based on the Return-Path
if header :contains "Return-Path" [
  "sendgrid.net"
  ]
{
    fileinto "Junk";
    stop;
}

#Not doing business in any of these countries, you can use wildcard
if address :domain :matches ["From"] ["*.za", "*.pe","*.sg","*.id","*.mk","*.cn","*.ua"]
{
  fileinto "Junk";
  stop;
}

Apply the filters to an account like this:

  cat /tmp/myfilters |xargs -0 zmprov ma info@example.com zimbraAdminSieveScriptBefore

Sieve rules defined in zimbraAdminSieveScriptBefore are applied before end-user rules and zimbraAdminSieveScriptAfter are applied after end-user rules. You can set zimbraAdminSieveScriptBefore and zimbraAdminSieveScriptAfter per account,cos,domain,server. If you set it on an a domain and on an account in that domain, the script on the account is used. To unset zimbraAdminSieveScriptBefore and zimbraAdminSieveScriptAfter on an account you can do:

  zmprov ma info@example.com zimbraAdminSieveScriptBefore ""
  zmprov ma info@example.com zimbraAdminSieveScriptAfter ""

Further reading

Jump to: navigation, search