Poco Script FAQ - Extracting information from incoming email

Poco Script FAQ - Extracting information from incoming email

For other solutions to this problem see:
Q: Can Poco be used to pull out data from a message body and export that data into a CSV file?
 
A: Yes, it can. The following outlines the basics of the techniques you would use to do this:

Assuming the email you will be receiving has been structured so that you can parse it then you will need to create a script to run against your incoming mail. This script will contain the rules for parsing the body of the email (extracted from the message by using the ReadBody command). You will need a series of "StringPos" and "If" statements to determine whether or not the keywords that define your elements are present. The basic structure would look something like:

ReadBody $body %message StringPos #a "keyword" $body If #a = 0 Then Chk0002 ... Here you will need to insert the code to extract the value from the body of the message. Use another StringPos to determine the location of the end delimiter and then extract the value using some of Poco'Script's string manipulation functions (ChopString, Trim, etc). Finally append the extracted value to a variable as a new line using the "InsertLine" command. Repeat these steps until you have parsed all the infromation from the body, then use the "WriteCSV" command to write the information out to a file. Once this is done you can run the external application using either the "Execute" or "ExecuteAndWait" commands.