How to Automate Lead Capture from Email

Stop copying leads from email to your CRM by hand. JsonHook delivers lead notification emails as structured JSON so your pipeline can create CRM records automatically within seconds.

Table of Contents
  1. Overview
  2. Prerequisites
  3. Step-by-Step Instructions
  4. Code Example
  5. Common Pitfalls

Overview

Lead capture automation is one of the highest-ROI applications of email-to-webhook processing. Many lead sources — website contact forms, ad platforms, partner referral systems — deliver new lead notifications via email. Without automation, those emails sit in a mailbox until someone manually copies the data into the CRM, introducing delay and risk of missed leads.

With JsonHook, every lead notification email is:

  1. Received at your JsonHook inbound address within seconds of the form submission
  2. Parsed into structured JSON (from, subject, body, headers)
  3. Delivered to your webhook handler
  4. Extracted and pushed to your CRM API or database
  5. The lead is in your CRM before the sales rep even sees the email

This pattern works for any CRM: HubSpot, Salesforce, Pipedrive, Airtable, a custom database, or all of the above simultaneously.

Prerequisites

Requirements for automated lead capture:

  • A JsonHook inbound address to receive lead notification emails
  • Sample lead notification emails from each source (examine them to understand the data format)
  • CRM API credentials and documentation (HubSpot API key, Salesforce Connected App OAuth token, etc.)
  • A webhook handler application (Express, FastAPI, Rails, etc.) or a no-code tool (Zapier, Make, n8n)

Automate Lead Capture in Your CRM

Lead email arrives. CRM record created. Sales notified. All automatically.

Get Free API Key

Step-by-Step Instructions

Build a lead capture pipeline:

  1. Collect sample lead emails. Gather 5-10 real lead notification emails from each source. Examine their structure to identify how to extract: name, email, phone, company, message, and any source-specific fields.
  2. Create a JsonHook address for lead emails, pointing at your lead capture webhook.
  3. Configure lead sources to send notifications to your JsonHook address (or forward existing notifications).
  4. Write extraction functions for each lead source format.
  5. Call your CRM API to create or update the contact record.
  6. Notify your sales team via Slack or email with the new lead details.
  7. Monitor extraction accuracy — log all extraction results and alert when required fields are missing.

Code Example

Lead capture handler that creates a HubSpot contact:

import express from "express";
import crypto from "crypto";
import fetch from "node-fetch";

const app = express();
app.use(express.raw({ type: "application/json" }));

function extractLeadFromEmail(email: any) {
  const text = email.textBody ?? "";
  const html = email.htmlBody ?? "";

  // Try to extract fields from structured notification format
  const emailMatch = text.match(/Email[:s]+([^s
]+@[^s
]+)/i);
  const nameMatch  = text.match(/Name[:s]+([^
]+)/i);
  const phoneMatch = text.match(/Phone[:s]+([+ds-()]{7,20})/i);
  const companyMatch = text.match(/Company[:s]+([^
]+)/i);
  const msgMatch   = text.match(/Message[:s]+([sS]{10,500})/i);

  return {
    email:   emailMatch?.[1]?.trim() ?? email.from.match(/[w.+%-]+@[w.-]+/)?.[0],
    name:    nameMatch?.[1]?.trim()  ?? null,
    phone:   phoneMatch?.[1]?.trim() ?? null,
    company: companyMatch?.[1]?.trim() ?? null,
    message: msgMatch?.[1]?.trim()   ?? text.slice(0, 300),
    source:  email.from,
  };
}

async function createHubSpotContact(lead: any) {
  const res = await fetch("https://api.hubapi.com/crm/v3/objects/contacts", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.HUBSPOT_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      properties: {
        email:     lead.email,
        firstname: lead.name?.split(" ")[0] ?? "",
        lastname:  lead.name?.split(" ").slice(1).join(" ") ?? "",
        phone:     lead.phone ?? "",
        company:   lead.company ?? "",
        message:   lead.message ?? "",
        hs_lead_status: "NEW",
      },
    }),
  });
  return res.json();
}

app.post("/webhooks/leads", async (req, res) => {
  // ... verify HMAC ...
  const { email, deliveryId } = JSON.parse(req.body.toString());
  const lead = extractLeadFromEmail(email);

  if (!lead.email) {
    console.warn(`No email found in lead payload ${deliveryId}`);
    return res.sendStatus(200);
  }

  const contact = await createHubSpotContact(lead);
  console.log(`Created HubSpot contact: ${contact.id} for ${lead.email}`);
  res.sendStatus(200);
});

app.listen(3000);

Common Pitfalls

Lead capture automation pitfalls:

  • Creating duplicate contacts. Check if the lead's email already exists in your CRM before creating a new record. Most CRM APIs support an upsert operation — create if not exists, update if exists — which prevents duplicates automatically.
  • Not handling multiple lead source formats. If leads come from multiple forms or platforms, each may have a different email format. Write separate extraction functions per source and route based on the sender address or a custom email header.
  • Missing leads due to extraction failures. If your regex fails to extract the lead's email from the notification body, the lead is lost. Log extraction failures prominently and send a fallback alert to your team with the raw email content.
  • CRM API rate limits. For high-volume lead capture (hundreds per minute), CRM API rate limits can cause failures. Buffer leads in your database first, then sync to the CRM at a rate-limited pace using a queue with rate limiting configured.
  • Not capturing the lead source. Store which JsonHook address / email sender the lead came from. This attribution data is valuable for measuring which lead sources are most productive.

Frequently Asked Questions

Which CRMs can I connect to via this approach?

Any CRM with an API: HubSpot, Salesforce, Pipedrive, Zoho CRM, Airtable, Monday.com, ActiveCampaign, and hundreds more. For no-code CRM integration, route your JsonHook webhook to Zapier or Make which have pre-built integrations for most CRM platforms.

How do I handle lead notifications from multiple different sources?

Create a separate JsonHook address for each lead source, each pointing to your webhook handler. In the handler, use the address ID or the sender address to determine which extraction function to apply. This avoids complex if-else chains trying to detect the format from the email content.

Can I capture leads without writing any code?

Yes. Route your JsonHook webhook to Zapier, Make, or n8n. These tools have HubSpot, Salesforce, and Pipedrive action steps that can create contacts from webhook data using their visual field mapping interface — no code required for standard lead fields.

How quickly does the lead appear in the CRM after form submission?

With JsonHook and a direct CRM API call, the contact typically appears in your CRM within 5–15 seconds of the form submission. The pipeline is: form submission → email sent by form provider (1–5 sec) → JsonHook receives and parses (1–2 sec) → webhook delivered (under 1 sec) → CRM API call (1–3 sec). Total: typically under 15 seconds.