text-extract-emails Edge Function — Content
ContentExtracts all valid email addresses from free-form text using an RFC 5321 compliant pattern. Supports deduplication and preserves order of first appearance.
Edge function text-extract-emails Extracts all valid email addresses from free-form text using an RFC 5321 compliant pattern. Supports deduplication and preserves order of first appearance.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/text-extract-emails Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "text-extract-emails",
args: {
"text": "example_text",
"unique": true
}
}) text-extract-emails — Extract Email Addresses from Text
Extracts all valid email addresses from any free-form text. Uses an RFC 5321 compliant pattern. Supports deduplication and preserves order of first appearance.
API
POST /api/text-extract-emails
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
text |
string | ✅ | — | Free-form text to extract email addresses from |
unique |
boolean | ❌ | true |
Deduplicate emails case-insensitively |
Success response (200)
{
"success": true,
"data": {
"emails": ["alice@example.com", "bob@domain.org"],
"count": 2
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing or invalid text field |
INTERNAL_ERROR |
500 | Unexpected processing error |
Usage
cURL
curl -X POST "$FUNCTION_URL/api/text-extract-emails" \
-H "Content-Type: application/json" \
-d '{"text": "Please contact alice@example.com or support@company.io for help."}'
TypeScript / JavaScript (HTTP)
const response = await fetch(`${FUNCTION_URL}/api/text-extract-emails`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: document,
unique: true,
}),
});
const { data } = await response.json();
console.log(data.emails); // ['alice@example.com', 'support@company.io']
console.log(data.count); // 2
Direct import (Node / Bun / Deno)
import { extractEmails } from '@aerostack/functions/text-extract-emails';
const result = extractEmails({
text: 'From: sender@example.com\nTo: recipient@example.org\nCC: cc@example.net',
unique: true,
});
console.log(result.emails); // ['sender@example.com', 'recipient@example.org', 'cc@example.net']
console.log(result.count); // 3
Use Cases
- Contact list building: Extract email addresses from pasted text, CSV files, or documents to build a mailing list.
- Email parsing pipelines: Extract sender/recipient addresses from raw email content or headers for routing and analytics.
- Web scraping: Pull contact emails from scraped web page content.
- Data cleaning: Extract and deduplicate email addresses from messy user-submitted text fields.
Notes
- Deduplication (
unique: true) is case-insensitive:Hello@Example.COMandhello@example.comare treated as the same address. The first occurrence is kept. - Emails are returned in order of first appearance in the text.
- Invalid patterns like
bad..email@example.com(consecutive dots in local part) are rejected. - The function does not validate whether a domain or mailbox actually exists — it only checks format validity.
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More Content Functions
Browse Content Functions →text-html-to-markdown
by @navin
Converts HTML to Markdown text. Handles headings, bold, italic, links, code, lists, blockquotes, and horizontal rules. Strips all other HTML tags while preserving text content.
text-markdown-to-html
by @navin
Converts Markdown text to HTML with optional sanitization. Supports all common Markdown syntax including headings, bold, italic, code blocks, lists, links, images, and blockquotes.
text-keyword-highlight
by @navin
Highlights keyword occurrences in text by wrapping them in configurable HTML tags. Handles case-insensitive matching, longest-match-first for overlapping keywords, and HTML entity escaping.
text-sanitize-html
by @navin
Sanitizes HTML by removing dangerous tags and attributes. Always strips script, style, iframe, form elements, and all event handlers. Keeps only whitelisted tags with whitelisted attributes.
text-slug-generate
by @navin
Generates a URL-safe slug from any string. Handles Unicode, accents, and special characters. Zero dependencies.
text-to-camel-case
by @navin
Converts a space-separated, snake_case, kebab-case, or PascalCase string to camelCase. Zero dependencies.
Frequently asked questions
What does the text-extract-emails function do? +
text-extract-emails is a serverless edge function for content automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the text-extract-emails function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/text-extract-emails ``` It will be live on Cloudflare Workers in seconds.
What runtime does text-extract-emails use? +
text-extract-emails runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the text-extract-emails function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.