How to conditionally run an action based on a script result

See also:
Running a C# script
An overview of scripting in Email Parser

Download this example

the Email Parser left panel running a condition with a script
In this example, we receive an email like the following:
Subject: Weather report

Temperature: 22.1
Temperature: 12.3
Temperature: -1.7
Temperature: 5.8

And after parsing the temperature values with a regular expression we run a script (once for each value) where we check if the temperature is above or below zero. Depending on the result of the script we export the captured text to one Google spreadsheet or another

The script we use creates a new field called “is_above_zero” that we will use later in the conditional action.

using System;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using EmailParserBackendApi.ScriptingInterface;
public class MyAction : ScriptBasedAction
	public override bool Run(MailMessage email, NameValueCollection fields)
        // Check if the database server is online
        if (float.Parse(fields["Temperature"])>0)
            fields.Add("is_above_zero", "yes");
            fields.Add("is_above_zero", "no");
        return (true);

In Email Parser, this script is placed under an action of type “Run a C# script”

running a script with email text

Then we evaluate the result of the script in the next action:

if a given text in an email meets a condition

And export to the corresponding spreadhseet the temperature value:

exporting email to a spreadsheet

When an email is received Email Parser runs all the items and produces the following output:

the output of an email being parsed capturing text from the body

© 2008-2024 Triple Click Software
News & Updates

Privacy Policy & Terms of Use
PAD file·Old news