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:
- Standard: [email protected]
- Subdomains: [email protected]
- Plus addressing: [email protected]
- Dots in local part: [email protected]
Using the Extract Emails API
TinyFn provides a simple endpoint to extract emails:
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
}
{
"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
- Deduplicate results: Remove duplicate emails for clean lists
- Validate format: Ensure extracted addresses are valid
- Respect privacy: Follow data protection regulations
- 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