Extract structured data from email

Automatically extract email data and send it to your CRM in a structured format.

Tags Streamline Icon: https://streamlinehq.com
Wrench Streamline Icon: https://streamlinehq.com
People Man Graduate Streamline Icon: https://streamlinehq.com

If you are doing any sort of customer support, sales, or marketing, you know email is a vast treasure trove of customer data. However, getting data from your email into your CRM can be a cumbersome experience, whether you have to install an expensive, clunky browser extension or manually copy/paste data from your email client into your CRM.

But this is now a thing of the past with AI and automation. In this tutorial, we’ll show you how you can automate this entire process using AI and Zapier. We’ll take an unstructured email from our inbox, pass it through one AI step, and store it directly into a table for future action, reporting, or other automation processes.

You’ll need:


  • Step 1: Connect your email account to Zapier
  • Step 2: Generate an OpenAI key
  • Step 3: Extract structured data from your email with OpenAI
  • Step 4: Send the structured data to your CRM
Products Give Gift 1 Streamline Icon: https://streamlinehq.com

Try before you bite?
This one's on us.

Sign up for a free account to view our free courses

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Step 1: Connect your email account to Zapier

Head over to Zapier to create a Zap automation that will monitor your email inbox based on a certain trigger.

To do this, go to Zapier, click the Zaps menu item on the left side, and click the Create button.

https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/663de85483598dae3f414996_Tutorial Content (48).png

For the trigger of your Zap, search and select your email provider of choice. We’ll be using Gmail in this tutorial.

For our Event, we’ll be using “New Labeled Email,” but you can choose from a set of options including, “New Email,” “New Email Matching Search,” and many others.

💡 Tip: For your email trigger, think about what is the lowest lift in terms of manual requirement, while at the same time, has the highest hit rate for ingesting only the emails you care about. For instance, if you’re using Gmail, you could create a rule that auto-labels email based on certain criteria and then pair it with the “New Labeled Email” trigger we used in this step.

I am going to use the label “CRM” for my Zapier trigger. This means any email that receives the label “CRM” in my inbox within two days of receipt, will trigger this workflow.

Once your trigger event is set, test it to ensure an email populates.

Step 2: Generate an OpenAI key

Next, we’ll need to generate an OpenAI key. This will be used in the following step within our Zap to extract structured data from our email. To do this, log in to platform.openai.com, then click ‘API’ to be taken to the developer platform.

https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/660ba95e9f800c74268c7e27_Tutorial Content (14).png

Click ‘API keys’ on the left menu, and click ‘Create new secret key’.

https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/660ba9673ebf70d6ce63d0db_Tutorial Content (15).png

Give it a name and click ‘Create secret key’. Once generated, copy it to your clipboard. Also, keep it secure; do not share it publicly as it gives access to your OpenAI account capabilities.

💡 Tip: You will need to add Credits to your OpenAI account in addition to creating an API key. To do this, navigate to Settings > Billing, add a payment source, and add at least the minimum credit balance to your account.

Step 3: Extract structured data from your email with OpenAI

Now that you have your OpenAI key, head back to your Zap in Zapier.

Click the Add a Step button, search and select ChatGPT from the app window, and set the Event to Extract Structured Data.

This is where you’ll need your OpenAI API key. On the Account tab, when you click Connect, a pop-up window will appear where you can paste in your OpenAI API key. Drop it into the top text box and then click Continue.

https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/663de92e39a7ebf2f06cce37_Tutorial Content (58).png

In the Action tab, select the email content you want to reference from your previous trigger step as the Unstructured Text. I’m going to use the “Body Plain” from my test email, but you can use items like the Email Subject, From Name, or any other elements from the email object you’d like to extract structured data.

Set the model to “gpt-3.5-turbo-16k” and leave the temperature to 0.0.

We’ll also need to add a description for the AI. The description is the base instruction of what we want it to do. For extracting structured text from our email content, we’ll provide the below prompt.

Sample prompt:

Convert the unstructured text provided into JSON.
💡 Tip: We’re keeping the temperature at 0.0 because we do not need much creativity/randomness from ChatGPT for this action. We’re also using GPT 3.5 because, for this type of action, we don’t need GPT-4 to get high levels of accuracy. This provides savings on our API bill, especially for high-volume actions like email ingestion.

Below the prompt, we’ll need to add the Values to Extract, which you can think of as the variables or field names of the content in your CRM you want to extract from your emails. To do this, add one variable to each row in this section. We’ve added Company Name, Product, Department, and Contact Name.

As the last step for the Action tab, you can provide ChatGPT with more information for each Value you provided on how it should think about the data. For Company Name, we used the below prompt.

Sample prompt:

The company name is the name of the corporation the email sender works for. They will either explicitly reference it in their email or it will be in the domain of their email address.
💡 Tip: We often set the requirement of each Value to Extract to be “False,” the data type to “string,” and leave the possible values blank. This provides the highest rate of success in parsing the data correctly. However, you can define these variables as needed based on your requirements.

Once you’ve added all the additional information for your Values, click over to the Test tab and give this step a test. If the output isn’t correct, tweak your Value instructions and re-test.

Step 4: Send the structured data to your CRM

For the last step in our Zap, we’ll add an action to send the data we extracted from our email to our CRM. For this example, we’ll be using Google Sheets, but you can select your CRM or database tool of choice for this step.

For the Action, we’ll need to map the output data from ChatGPT to the fields in our Google Sheet.

Give this step a test and you should see the structured data populating your Google Sheets, CRM, or database of choice.

And that’s it! Publish your Zap when you’re ready, and you’ll be streaming structured data directly from your email inbox to your CRM.

This tutorial was created by Garrett.

Get full access

✔️ All 100+ courses & tutorials in our catalog
✔️ New content added weekly
✔️ Private community access
✔️ No subscription, $150 paid once
✔️ Expense it using this template. Or get a team account.
✔️ 30-day refund policy. No questions asked
Join 3,107 learners from companies like Microsoft, Coca Cola, NBA, Adobe & Google

More tutorials like this

View all

If you scrolled this far, you must be a little interested...

Start learning ->

Join 3,107 professionals already learning