Aerostack
edit

text-extract-emails Edge Function — Content

Content

Extracts all valid email addresses from free-form text using an RFC 5321 compliant pattern. Supports deduplication and preserves order of first appearance.

navin @navin verified
Updated Mar 12, 2026
GitHub

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.

terminal — aerostack cli
$ npx aerostack add navin/text-extract-emails
smart_toy

Use with AI Assistants

MCP

Connect 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.

claude_desktop_config.json
{
  "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
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.COM and hello@example.com are 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

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

text
deployed_code

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 →

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.