Extract structured data from email
Automatically extract email data and send it to your CRM in a structured format.
2024-11-13
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:
- Zapier paid plan
- OpenAI API
- Google Sheets (or a CRM of your choice)
- Email account
Steps:
- 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
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.
.webp)
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.
.webp)
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.
.webp)
Once your trigger event is set, test it to ensure an email populates.
.webp)
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.
.webp)
Click ‘API keys’ on the left menu, and click ‘Create new secret key’.
.webp)
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.
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.
.webp)
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.
.webp)
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.
.webp)
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.
.webp)
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.
.webp)
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.
.webp)
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.
.webp)
For the Action, we’ll need to map the output data from ChatGPT to the fields in our Google Sheet.
.webp)
Give this step a test and you should see the structured data populating your Google Sheets, CRM, or database of choice.
.webp)
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.