Filter - Custom DRE Functions

Custom Function

Zoho Mail Filters now support Custom Functions via Deluge Scripting in Zoho creator. This allows you to customize the Filter Conditions and Actions using multiple parameters. This helps you to create and write Simple Deluge scripts, to create custom Actions and set them as Conditions or Actions in your Filters in Zoho Mail. Further, this enables you to setup Workflows which can be triggered by emails based on specific conditions and customizable actions.

Gallery Functions:

Gallery Functions are readymade scripts available to you to install and use directly. Certain gallery functions published there might need some little customizations to make them applicable to your exact scenario or use case. These pre-written functions also serve as a reference for retrieving the mail related parameters or actions related to mail, when you write your own custom Deluge scripts. 

Steps to Add Custom Actions in Filters: 

  1. Login to Zoho Mail
  2. Click the Settings  icon.
  3. Go to Filters
  4. Click New Filter to add a new filter.
  5. Provide the basic conditions (Example: Sender/ Subject etc)
  6. In the actions, select 'Custom function (Creator)' from the drop-down. 
  7. Click Select Function to view the Deluge Script editor popup. 
  8. You can create your own functions or choose a gallery function here. 
  9. Once you create your own set of functions, you can directly choose them in the Action area. 

Zoho Mail in Deluge:

Zoho Mail provides certain actions in Deluge to retrieve metadata information of the current user/ the related email that can be retrieved via Deluge Script:

Lists all  Folders for the given account, as a map
ID- FolderID

Lists all labels for the given accounts, as a map
ID- LabelID
COLOR in Hexadecimal

messageID is the required parameter.
Gets message details as a MAP.

Here are the key parameters available in the MAP,

CC - Cc email address 
RDT - Received Date and Time
BCC - Bcc Email Address
SENDER - Sender email address 
INREPLYTO - If the email is a reply to another email, the MailId of the original email will be available in this parameter. 
MAILID - Unique Mail ID of this email. 
PRIORITY - Priority in which the email is received.  
FROM - From email address in the email
SENTTIME -  Date and Time at which the email was sent
SENTTIMEINMILLIS - Sent time converted to long value as Milli seconds
SUBJECT - Email Subject
TO - To email Address of the email 
CONTENT - Email Content 
RETURNPATH - Return path of the email, if the email was bounced back. 

Sample Output:

{MAILID=<>, SUBJECT="Wow this is amazing!", SENTTIME=Thu, 28 Jan 2016 11:28:22 +0530,, PRIORITY=3, SENTTIMEINMILLIS=1453940902000, TO= &lt;;, RDT=Thu, 28 Jan 2016 11:28:27 +0530, BCC=, INREPLYTO=, CONTENT=, CC=, STATUS2ID=0,, RETURNPATH=<>, conv=true, SHRINKED=false}"

Actions supported in Zoho Mail via Deluge Script: 

messageId and toFolderName/ toFolderId are the required parameters. (toFolderName is the destination folder name to which the email should be moved)
zoho.mail.moveToFolder(mail_messageId, "/toFolderName") OR zoho.mail.moveToFolder(mail_messageId, toFolderId)


  • If the destination folder is a sub-folder, the entire path of the folder has to be mentioned in the Folder Name.
    Ex: "/Inbox/Marketing/Design"

messageId and TagName/ TagId are the required parameters. (TagName is the name of the tag which should be applied to that email.)
zoho.mail.setTag(mail_messageId, "TagName") OR zoho.mail.setTag(mail_messageId, TagId)

folderName and parentFolderId are the needed parameters for this action. Folder name is the name of the folder name to be created and parentFolderId is needed if the folder is a subfolder to another folder. 
zoho.mail.createFolder(folderName, parentFolderId)

markAsRead - Marks the particular email as Read
markAsUnread - Marks the particular email as Unread
removeFlag - removes any Flag applied to the message.

For the above 3 functions messageId is the required parameter.

AND / OR Conditions in Filter: 

Currently, Zoho Mail filters do not directly support a combination of OR and AND usage between multiple conditions. In case you have such custom requirement, you can create and use Deluge scripts in Custom Actions to organize your Inbox or create a custom rule for such emails. 

Ex: You can create a filter with conditions like below:

If (sender = <> or sender=<>) and subject = subject1 then move email to the folder <folder x>. 

Custom Workflows:

Custom Action support in Zoho Mail helps you to integrate Zoho Mail with other Zoho applications or external applications and create workflows based on incoming emails. 


If Subject = "Contact us" or To = "" then Add Sender as a lead in Zoho CRM. 

If Subject = "Invoice xxxx" then extract total amount and Add it to the database <abcde> in Zoho Reports. 

Content based Filters: 

The default email filter conditions support only the parameters available in the email metadata. Hence it is not possible to create filters with 'Content' based conditions. With Custom Actions in place, you can write your script to create Content based conditions and actions for incoming emails to organize them better or create custom workflows. 

Sample Scripts:

Chain Actions in a single custom function

// To get the email data, use the 'mail_messageId' parameter
// sent from mail filter when calling the Dre function.

messageDetails = zoho.mail.getMessage(mail_messageId);
mailContent = messageDetails.get("CONTENT");
mailSubject = messageDetails.get("SUBJECT");
fromAddress = messageDetails.get("FROM");
moveToFolderPath = "/ToDoList";
myTask = 123456;
othersTask = 234567;

Get the Label Details for a given label name:

tagId= -1;
tagDetails = zoho.mail.getLabels();
        for each  tag in tagDetails
            if(tag.get("NAME") == "High Priority")
                tagId = tag.get("ID");


Convert SentDateTime parameter to Creator Date Time format

Time zone has to be changed in accordance with TimeZone in Input Parameter

messageDetails = zoho.mail.getMessage(mail_messageId);
mailDate = messageDetails.get("SENTTIME");
mailDateString = mailDate.toDate("E, dd MMM yyyy HH:mm:ss +0530");  //gives output in format 20-Apr-2017
mailDateTimeString = mailDate.toTime("E, dd MMM yyyy HH:mm:ss +0530");  //gives output in format 20-Apr-2017 13:23:06 

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: