Extract Emails API: The Complete Guide

Need to extract email addresses from text? This guide covers everything you need to know about email extraction via API, including validation, deduplication, and handling edge cases.

What is Email Extraction?

Email extraction identifies and extracts all email addresses from unstructured text. This is useful for lead generation, data processing, and contact management. A robust extractor handles various email formats while filtering invalid addresses.

Example: "Contact us at [email protected] or [email protected]" extracts ["[email protected]", "[email protected]"]

Email Format Considerations

Valid email addresses can have various formats:

Privacy Note: Always handle extracted email addresses responsibly and in compliance with data protection regulations like GDPR.

Using the Extract Emails API

TinyFn provides a simple endpoint to extract emails:

API Request
POST https://api.tinyfn.io/v1/text/extract-emails
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "text": "Contact [email protected] or [email protected] for more info.",
  "unique_only": true
}
Response
{
  "emails": [
    "[email protected]",
    "[email protected]"
  ],
  "count": 2,
  "domains": ["example.com", "example.org"]
}

Parameters

Parameter Type Description
text string The text to extract emails from (required)
unique_only boolean Return only unique emails (default: true)
lowercase boolean Convert emails to lowercase (default: true)
validate boolean Validate email format strictly (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/text/extract-emails',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'your-api-key',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      text: 'Contact [email protected] or [email protected]',
      unique_only: true
    })
  }
);
const result = await response.json();
console.log(result.emails); // ["[email protected]", "[email protected]"]

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/text/extract-emails',
    headers={'X-API-Key': 'your-api-key'},
    json={'text': 'Contact [email protected] or [email protected]'}
)
result = response.json()
print(result['emails'])  # ["[email protected]", "[email protected]"]

cURL

curl -X POST "https://api.tinyfn.io/v1/text/extract-emails" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"text": "Contact [email protected] or [email protected]"}'

Common Use Cases

  • Lead Generation: Extract contacts from web pages
  • Data Migration: Parse emails from legacy documents
  • Email List Building: Compile mailing lists from various sources
  • Contact Import: Extract emails from business cards or PDFs
  • Compliance: Identify emails in documents for GDPR compliance

Best Practices

  1. Deduplicate results: Remove duplicate emails for clean lists
  2. Validate format: Ensure extracted addresses are valid
  3. Respect privacy: Follow data protection regulations
  4. Handle edge cases: Consider obfuscated emails (e.g., "user at domain dot com")

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-text": {
      "url": "https://api.tinyfn.io/mcp/text/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all text analysis tools available via MCP in our Text Analysis MCP Tools for AI Agents guide.

Try the Extract Emails API

Get your free API key and start extracting emails in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key