Extracting data from emails and attachments at scale is a common business requirement. You may want to turn product orders, shipping updates, and invoices into structured data in databases, and spreadsheets. This process typically involves manual labelling or flaky code-based parsing. MailSlurp's AI Transformers make solving this problem easy by combining inboxes, JSON schema definitions, and AI models into one seamless pipeline.

Executive summary

  • MailSlurp AI pipelines turn emails and attachments into structured data
  • Define desired outputs with JSON schemas, or use a prompt like
  • Connect inboxes to transformers and automatically parse inbound content
  • Data is stored in tables for fetching or sent to your system via webhook
  • AI transformers can also be directly invoked using the API and an email ID

An example

Let's demonstrate with an example that takes Amazon shipment tracking emails and converts them into tables of structured data with properties like: , and array. A typical email of this sort is as follows:

We will create an AI pipeline to turn shipment emails into data we can analyze. This automation will work by attaching AI prompts to inbound emails using an email address we create in MailSlurp or connect via Gmail. When matching emails are received by the inbox they will trigger our AI transformer, the prompts and output schemas will be sent to LLMs and the outputs will be stored in a table. Then end result should look something like this:

Creating an AI transformer

We can create a transformer using the API or in the MailSlurp dashboard. First navigate to the page then click create transformer.

Next we can choose to create the pipeline from scratch or based on an existing email or attachment. Let's do the latter. Selecting that option will display a page with a new email address and instructions for sending your email. Send an email to the given address or select an email from the dropdown selector if you already have one in your MailSlurp account. We will send our Amazon order delivery email so we can build a spreadsheet of shipment tracking data.

Configuring inputs

Once we have email the transformer's inbox we are presented with a preview of the email and a configuration page. We can use this to setup the input mapping and the transformation. The input mapping tells MailSlurp which emails to apply the transformation to. Here we will add a filter for emails with the subject containing . We also tell MailSlurp to trigger the pipeline when any matching email is received in any of our inboxes.

With MailSlurp you can create unlimited email addresses or connect Gmail and Outlook accounts directly. AI transformation data can be connected directly to your systems or exported as Excel, CSV, XML, and more.

Defining prompts and output

With our inputs configured we can now specify the data we wish to extract from emails matching our input filters. We can do this in two ways 1) using a prompt in natural language, or 2) by defining a JSON schema. With a prompt we simply write what properties we want to find in an email and the data types we expect them to be.

Using a prompt

We will write some instructions for the AI and specify the properties and data types we want to extract from the Amazon shipment emails. We want data that tracks order numbers, items, quantity, pricing, and expected arrival dates. We enter these instructions into the prompt box like so:

For more precise control over output structure use the JSON schema builder interface. You can define properties and types explicitly and provide additional instructions and examples.

Testing our schema

The prompt input panel has an email preview pane on the right. We can use this to refine our instructions by clicking test prompt. This will execute the AI transformation on the given email and show us the end result. Once we have refined our prompt we know it will work for other emails that are similar.

This will send the email we selected plus our prompt and instructions to the MailSlurp LLM models and returned the data outputs. In our example the prompt generates the follow shipment tracking data:

The data output is shown as JSON code but we can view the end results in many formats including visual tables, CSV, Excel spreadsheets and more.

Once we are happy with the data and prompt we can save our pipeline.

Using our pipeline

Now that we have defined a pipeline for turning delivery tracking email into actionable data we forward relevant emails to our MailSlurp inbox:

forward-emails-ai.png

Once the emails are received by MailSlurp they will be evaluated as input matches in our transformer. If they match (which in our cases means having a subject containing ) their content and our instructions will be passed to the MailSlurp AI models and subsequent data will be stored as AI transform results. The results can be viewed in the MailSlurp dashboard as a table like so:

Connecting and using data

Once we have data streaming in from our AI pipeline we can either view it in th dashboard, export is in various formats (like Excel and CSV) or connect it to other systems. With webhooks you can tell MailSlurp to send any new AI data to your server endpoints upon creation. An example webhook looks like this:

Example summary

In this post we demonstrated how AI transformer pipelines can turn emails and attachments into useful data. We attached a transformer to our MailSlurp inbox and defining matching subject filters for incoming shipments. Next we used a prompt to determine the properties and data types we wished to extract from inbound delivery emails. We tested the prompt on an example email and refined the outputs. Once saved newly received shipment emails were automatically processed and the shipping data was stored in a table for us.

Next steps

AI transformers have unlimited applications and are available with any base plan on MailSlurp. For a demo or to talk to our sales team please reach out to us. You can create a free account today to get started.