How to filter emails with a script

C# scripts are not supported in the Web app See the item compatibility table

See also:
Using scripts to filter emails
Scripting in EmailParser. An Overview

Download this example

This example shows how filtering with a C# script works in the Email Parser Windows App. If the email contains two .jpg attachments the filter is passed, otherwise the email is rejected. The overview of the left panel is as follows:

script for email filtering

If we open the filter settings the checkbox to enable script filtering is activated and the script is shown below:

script for email filtering

The full script is:

using System;
using System.Net.Mail;
using EmailParserBackendApi.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

© 2008-2024 Triple Click Software
News & Updates

Windows App privacy police and terms of use
Web App privacy police and terms of use

This site privacy police and terms of use
PAD file·Old news