Brian Dunning's FileMaker Custom Functions

EMLtoJSON ( emailText ; header )

Parses .EML formatted text to read header or body values, or return entire email as a JSON object

  Average rating: 5.0 (1 vote) Log in to vote

Michael Kupietz   Michael Kupietz - Show more from this author
Michael Kupietz FileMaker Consulting
https://michaelkupietz.com

Share on Facebook Share on Twitter

  Sample input:
EMLtoJSON ( [field containing text from an .eml file] ; "" )
  Sample output:
{ "from": "john@smith.com",
"to" : "alice@vooyrn.com",
"subject" : "hello there",
"received" : [ "received header 1" , "received header 2" , "received header 3"],
"body" : "Hello there Alice, I am a spammer writing to fill your inbox with nonsense. Would you like to buy a left-handed veeblefetzer from me?" }

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This function takes a block of text from an .eml file and parses it. You can request a specific header value as follows, for example for the "To" header value as text:

EMLtoJSON ( [field containing text from an .eml file] ; "To" )

You can also request the body as text:

EMLtoJSON ( [field containing text from an .eml file] ; "Body" )

Or, if you leave the header blank, it will return the entire email as a json object, with the header names as keys and their values as the JSON values. For headers that appear more than once, such as "Received: ", it will only create one key, but the values will be listed as a JSON array of all values found. It will also append a "body" key with the value set to the text of the body.

If you have the .eml file stored in a container field, you can convert it to text to pass to this function with TextDecode(ContainerField, "UTF-8").

 

Comments

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: