📝 Documentation Update in Progress
We released a significant update to Email Parser in January 2026. We are currently working on updating our documentation to match the latest version. Some pages may reference older features or interface elements.

Capturing text with a C# script

Note: C# scripts are only supported in the Windows desktop application. The web app does not support running C# scripts. See the compatibility table for a full comparison.

See also:
Overview of scripting in Email Parser
Email Parser scripting SDK
Example – Basic use of a script to capture text from an email

running a C# script to parse email text

Most text capturing tasks can be done with “AI parse” or “Start with… continues until…” but for very specific cases you may need to write a script that captures the required information from the received email.

To capture text with C# in Email Parser, all you need to do is implement the ExtractTextFrom() method in the sample script that appears by default in the code editor. Email Parser handles all the plumbing: it feeds this method with the email data and automatically collects any text strings that the method returns.

Writing your script outside Email Parser

The code editor built into Email Parser is intentionally minimal. It is not meant for writing or debugging code. Think of it simply as a place to paste your finished script. Do your actual development in a proper code editor: Visual Studio and Visual Studio Code are the most popular choices for C# development. For quick edits or simple tests, online tools such as .NET Fiddle and SharpLab are also very handy and require no installation.

.NET dependencies (DLL files)

By default, Email Parser loads your script with the most common .NET assemblies already referenced (things like string handling, collections, and file I/O) so you can start writing code without worrying about dependencies for everyday tasks.

However, for more specialized needs you may need to add your own DLL references. For example, if you want to work with JSON data, you might need to reference System.Text.Json.dll. To add a DLL, click the DLL button on the right side of the code editor inside Email Parser. Standard .NET runtime assemblies can typically be found at C:\Program Files\dotnet\shared.

Referencing .NET assemblies (DLL files) in the Email Parser C# script editor
Example

The following script shows a basic example of text capturing using C#. It searches the input text for the marker "Message:" and, if found, extracts everything after it (trimming any leading or trailing whitespace). If the marker is not present in the input, the script returns the string "No match found":

//
// Implement the ExtractTextFrom() method below to capture text from the input_text parameter.
// In the diagram, inside the parser box, follow the arrow backwards from this field to the top
// row to find the input field. The input_text parameter contains the text from that field.
//
// This script uses .NET 7. You can reference any .NET library using the DLL button in the editor.
// This method typically returns a list containing a single string, but it can also return multiple values.
//
// Use the Print() method to log messages to the Email Parser 'Activity' tab.
//
// We recommend using a full IDE like Visual Studio Code to develop and debug your code.
// Once finished, paste your code here.
//
// For more information, see the Email Parser documentation at:
// https://www.emailparser.com/d/email-parser/capturing-text-scripts

using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
using EmailParserBackend.ScriptingInterface;

public class MyScriptBasedEmailParser : ScriptBasedField // The class name should remain unchanged
{
    public override List<string> ExtractTextFrom(string input_text)
    {
        // This example finds the "Message:" marker in the input text using the IndexOf method.
        // If the marker is found, the text from this point to the end of the string is extracted using Substring and any leading whitespace is removed.
        // If the marker is not found, the function returns a list containing "No match found". 
        string startMarker = "Message:";
        int startIndex = input_text.IndexOf(startMarker);

        if (startIndex != -1)
        {
            string message = input_text.Substring(startIndex + startMarker.Length).Trim();
            return new List<string> { message };
        }
        else
        {
            return new List<string> { "No match found" };
        }
    }
}

© 2008-2026 Triple Click Software Ltd.
News & Updates·Service status

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