---
title: "Extract structured data from email"
slug: "extract-structured-data-from-email"
date: "2024-11-13"
updated: "2024-11-13"
status: "published"
featured: false
access: "pro"
difficulty: "intermediate"
one_liner: "Automatically extract email data and send it to your CRM in a structured format."
tools: ["ChatGPT", "Zapier", "Google Sheets"]
topics: ["CRM", "Email"]
roles: ["AI/Machine Learning Engineer"]
categories: ["Productivity & Workflow Optimization"]
---

<!-- migrated_from_webflow_csv -->

<!-- UNRESTRICTED -->

<div class="unrestricted">

<p id="">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.</p><p id="">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.</p><p id=""><strong id="">You’ll need:</strong></p><ul id=""><li id=""><a href="https://zapier.com/" id="">Zapier</a> paid plan</li><li id=""><a href="https://platform.openai.com/" id="">OpenAI API</a></li><li id=""><a href="https://docs.google.com/spreadsheets/u/0/" id="">Google Sheets</a> (or a CRM of your choice)</li><li id="">Email account</li></ul><p id=""><strong id="">Steps:</strong></p><ul id=""><li id="">Step 1: Connect your email account to Zapier</li><li id="">Step 2: Generate an OpenAI key</li><li id="">Step 3: Extract structured data from your email with OpenAI</li><li id="">Step 4: Send the structured data to your CRM</li></ul>

</div>

<!-- RESTRICTED -->

<div class="restricted" data-access="pro">

<h4 id="">Step 1: Connect your email account to Zapier</h4><p id="">Head over to <a href="https://zapier.com/" id="">Zapier</a> to create a Zap automation that will monitor your email inbox based on a certain trigger.</p><p id="">To do this, go to Zapier, click the Zaps menu item on the left side, and click the Create button.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3828px" data-rt-type="image" style="max-width:3828px"><div><img alt="https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/663de85483598dae3f414996_Tutorial Content (48).png" height="auto" id="" loading="auto" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/672669e012b2d014e636fa32_67263b348fe975b6aac5d7cc_(48).webp" width="auto"/></div></figure><p id="">For the trigger of your Zap, search and select your email provider of choice. We’ll be using Gmail in this tutorial.</p><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3834px" data-rt-type="image" style="max-width:3834px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520c1_67263b81b99f606d08370088_(66).webp"/></div></figure><div data-rt-embed-type="true"><div style="padding: 20px; margin: 10px 0; background-color: #ffe8ed; border-left: 5px solid #f78ae0;"><strong>💡 Tip:</strong> 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.</div></div><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1320px" data-rt-type="image" style="max-width:1320px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520a9_64313caad2dce3781a32b22_Tutorial_Content_(67).webp"/></div></figure><p id="">Once your trigger event is set, test it to ensure an email populates.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1294px" data-rt-type="image" style="max-width:1294px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520bb_64313d442dcd47f12c531f5_Tutorial_Content_(68).webp"/></div></figure><h4 id="">Step 2: Generate an OpenAI key</h4><p id="">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 <a href="https://platform.openai.com/apps" id="">platform.openai.com</a>, then click ‘API’ to be taken to the developer platform.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3056px" data-rt-type="image" style="max-width:3056px"><div><img alt="https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/660ba95e9f800c74268c7e27_Tutorial Content (14).png" height="auto" id="" loading="auto" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/672669df12b2d014e636fa19_6726394ac38c28458b4755eb_(14).webp" width="auto"/></div></figure><p id="">Click ‘API keys’ on the left menu, and click ‘Create new secret key’.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3056px" data-rt-type="image" style="max-width:3056px"><div><img alt="https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/660ba9673ebf70d6ce63d0db_Tutorial Content (15).png" height="auto" id="" loading="auto" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/672669e012b2d014e636fa4a_6726394bc38c28458b475611_(15).webp" width="auto"/></div></figure><p id="">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.</p><div data-rt-embed-type="true"><div style="padding: 20px; margin: 10px 0; background-color: #ffe8ed; border-left: 5px solid #f78ae0;"><strong>💡 Tip:</strong> You will need to add Credits to your OpenAI account in addition to creating an API key. To do this, navigate to Settings &gt; Billing, add a payment source, and add at least the minimum credit balance to your account.</div></div><h4 id="">Step 3: Extract structured data from your email with OpenAI</h4><p id="">Now that you have your OpenAI key, head back to your Zap in Zapier.</p><p id="">Click the Add a Step button, search and select ChatGPT from the app window, and set the Event to Extract Structured Data.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3834px" data-rt-type="image" style="max-width:3834px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520be_67263b81b99f606d08370072_(69).webp"/></div></figure><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-center" data-rt-align="center" data-rt-type="image"><div><img alt="https://assets-global.website-files.com/65d4bab2989b365c8d09a9ea/663de92e39a7ebf2f06cce37_Tutorial Content (58).png" height="auto" id="" loading="auto" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/672669e012b2d014e636fa38_7263b348fe975b6aac5d7a6_Tutorial_Content_(58).webp" width="auto"/></div></figure><p id="">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.</p><p id="">Set the model to “gpt-3.5-turbo-16k” and leave the temperature to 0.0.</p><p id="">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.</p><p id=""><strong id="">Sample prompt:</strong></p><blockquote id="">Convert the unstructured text provided into JSON.</blockquote><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1314px" data-rt-type="image" style="max-width:1314px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520a4_7263b81b99f606d08370066_Tutorial_Content_(70).webp"/></div></figure><div data-rt-embed-type="true"><div style="padding: 20px; margin: 10px 0; background-color: #ffe8ed; border-left: 5px solid #f78ae0;"><strong>💡 Tip:</strong> 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.</div></div><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1318px" data-rt-type="image" style="max-width:1318px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520b5_67263b81b99f606d08370063_(71).webp"/></div></figure><p id="">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.</p><p id=""><strong id="">Sample prompt:</strong></p><blockquote id="">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.</blockquote><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1306px" data-rt-type="image" style="max-width:1306px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520ac_7263b81b99f606d0837006b_Tutorial_Content_(72).webp"/></div></figure><div data-rt-embed-type="true"><div style="padding: 20px; margin: 10px 0; background-color: #ffe8ed; border-left: 5px solid #f78ae0;"><strong>💡 Tip:</strong> 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.</div></div><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1322px" data-rt-type="image" style="max-width:1322px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520b8_7263b81b99f606d0837005d_Tutorial_Content_(73).webp"/></div></figure><h4 id="">Step 4: Send the structured data to your CRM</h4><p id="">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.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3832px" data-rt-type="image" style="max-width:3832px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520c4_67263b81b99f606d08370085_(74).webp"/></div></figure><p id="">For the Action, we’ll need to map the output data from ChatGPT to the fields in our Google Sheet.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="1316px" data-rt-type="image" style="max-width:1316px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520af_6431448ba1a9a59d1f61a11_Tutorial_Content_(75).webp"/></div></figure><p id="">Give this step a test and you should see the structured data populating your Google Sheets, CRM, or database of choice.</p><figure class="w-richtext-figure-type-image w-richtext-align-fullwidth" data-rt-align="fullwidth" data-rt-max-width="3008px" data-rt-type="image" style="max-width:3008px"><div><img alt="__wf_reserved_inherit" loading="lazy" src="https://cdn.prod.website-files.com/66eeba0c7a01b10910c883da/67266a407c3de58c466520b2_7263b81b99f606d0837005a_Tutorial_Content_(76).webp"/></div></figure><p id="">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.</p><p id="">This tutorial was created by <a href="https://garretthoughton.com/" id="">Garrett</a>.</p><p>‍</p>

</div>
