Email Parser

Extract data from incoming emails and automate your workflow

Basic use of a script to filter emails

 

This example shows a basic script-filter example. If the email contains two .jpg attachment the filter is passed, otherwise the email is rejected.

 

example_31_leftpanel
Download this example

 

 

using System;
using System.Net.Mail;
using EmailParserBackend.ScriptingInterface;
public class MyFilter : ScriptBasedEmailFilter
{
  public override bool FilterEmail(MailMessage msg)
  {
        // Check if the email contains two attachments
        if (msg.Attachments.Count != 2)
        {
            // Reject the email and finish
            return (false);
        }
        // Check if the two attachments are jpg files
        if (msg.Attachments[0].Name.Contains(".jpg") &&
            msg.Attachments[1].Name.Contains(".jpg"))
        {
            // Accept the email and finish
            return (true);
        }
        else
        {
            // Reject the email and finish
            return (false);
        }
  }
}

 

It produces the following output for an email that passes the filter:

example_31_output