fbpx

Basic use of a script to capture text from an email

This example extracts the first word of the email body. It also opens a TXT file and stores its contents as a field.  

Download this example

    The field first_word_of_email_body uses the following script:
using System;
using System.Text;
using System.Collections.Generic;
using EmailParserBackend.ScriptingInterface;
 
public class MyScriptBasedEmailParser : ScriptBasedParser
{
	//
	// Modify this method to implement your own text capture
	//
	public override List<string> ExtractTextFrom(string input_text)
	{
        List<string> returned_values = new List<string>();
 
        // Get the first word of the incoming email
        char[] valid_word_separators = new char[] { ' ', ',', '.', ':' };
        string[] words = input_text.Split(valid_word_separators);
        returned_values.Add(words[0]);
 
        return(returned_values);
	}
}
  And the script for txt_file_contents is:
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using EmailParserBackend.ScriptingInterface;
 
public class MyScriptBasedEmailParser : ScriptBasedParser
{
	public override List<string> ExtractTextFrom(string input_text)
	{
        List<string> returned_values = new List<string>();
 
		// Read the local TXT file C:\test\test.txt and add its contents as a new field
        string txt_file_contents = File.ReadAllText(@"C:\test\test.txt");
 
 
        returned_values.Add(txt_file_contents);
 
        return(returned_values);
	}
}
    Clicking run we get the following output:   example_32_output

© 2008-2021   FrozenFrog Software    PAD file     Privacy Policy & Terms of Use