Using Sieve to send email notifications

You can set up Zimbra to send notifications to a different email address for emails that arrive in your Inbox or any folder via the Preferences panel:

You can also create a filter to forward emails to a specified email address using the Filters panel:

In this article you will learn how to use Sieve to send a mail notification, this way you can use more advanced conditions for sending the notification.

Using Sieve to send a mail notification

In this first example we set-up a simple notification, the aim is to send a notification to external-user@zimbra.nl whenever an email is received by admin@zimbra.tech. Please note that the notification Sieve script can not be changed by the user.

First create a file /tmp/myfilters with the following contents:

require ["enotify","variables"];

set "subject" "Test Subject";
set "contents" "Hello World
You've got a mail
Chao!";

if anyof (true) {
  notify :message "${subject}" :from "admin@zimbra.tech" :importance "2" "mailto:external-user@zimbra.nl?Importance=High&X-Priority=1&X-HEADER1=value1&From=admin@zimbra.tech&body=${contents}";
  keep;
}

Run as the user zimbra the following commands:

zmprov ma admin@zimbra.tech zimbraSieveNotifyActionRFCCompliant TRUE
cat /tmp/myfilters |xargs -0 zmprov ma admin@zimbra.tech zimbraAdminSieveScriptBefore

To test and debug your Sieve script you can run the following command to see the error log:

tail -f /opt/zimbra/log/mailbox.log

Then send a test email to admin@zimbra.tech (in this example) and see if you receive the notification on the external address, the notification should look like this:

In this example the condition for the notification is set as if anyof (true) this means the condition is always true. If this notification works you can change the conditions, here are some examples:

#based on Subject:
if header :contains "Subject" ["Some Subject"]
{
   #put notification code from above here
}

#based on from/sender fuzzy
if address :contains ["from", "sender"] ["user1@example.com","user3","someorg"]
{
   #put notification code from above here
}


#based on a from/sender domain
if address :is :domain ["from", "sender"] ["example.com","example.io"]
{
   #put notification code from above here
}

#you can also combine such as:
if allof(
   address :is :domain ["from", "sender"] ["example.com","example.io"],
   header :contains "Subject" ["Some Subject"]
)
{
   #put notification code from above here
}

 

One Response to Using Sieve to send email notifications

  1. Shubham March 27, 2024 at 11:02 AM #

    Such a useful tool to send email without any time-consuming manual work. Most of my affiliate marketing happens through email and this is what I would be implementing from now on. Thank you to the team at Zimbra!

Leave a Reply

Copyright © 2022 Zimbra, Inc. All rights reserved.

All information contained in this blog is intended for informational purposes only. Synacor, Inc. is not responsible or liable in any manner for the use or misuse of any technical content provided herein. No specific or implied warranty is provided in association with the information or application of the information provided herein, including, but not limited to, use, misuse or distribution of such information by any user. The user assumes any and all risk pertaining to the use or distribution in any form of any subject matter contained in this blog.

Legal Information | Privacy Policy | Do Not Sell My Personal Information | CCPA Disclosures