# Send Email from Your Agent

Wire Wraps into your agent's tool calls. The infrastructure lives in your AWS account; the agent just calls a typed function.

## What You'll Build

- AWS SES deployed to your account (DKIM, SPF, DMARC included)
- A typed send-email tool your agent framework can register as-is
- Wraps docs in your AI editor's context via Context7 MCP
- Live access to your email infrastructure via the Wraps MCP server

Time: ~5 minutes

## Prerequisites

- Node.js 20 or later
- An AWS account with valid credentials configured
- An agent framework (LangGraph, Vercel AI SDK, Mastra, or your own)

## Step 1: Deploy Infrastructure

```bash
npx @wraps.dev/cli email init
```

Deploys SES, DKIM, bounce handling, and EventBridge event processing into your AWS account.

## Step 2: Install the SDK

```bash
npm install @wraps.dev/email
# or: pnpm add @wraps.dev/email | yarn add @wraps.dev/email | bun add @wraps.dev/email
```

## Step 3: Write the Agent Tool

```typescript
import { WrapsEmail } from "@wraps.dev/email";

const email = new WrapsEmail();

// Works for any agent framework:
// LangGraph: register as a tool. Vercel AI SDK: pass to tool({}).
// Mastra: wrap with createTool. The signature stays the same.
export async function sendEmailTool(input: {
  to: string;
  subject: string;
  html: string;
}) {
  const result = await email.send({
    from: "agent@yourdomain.com",
    to: input.to,
    subject: input.subject,
    html: input.html,
  });

  if (!result.success) {
    throw new Error(`Email failed: ${result.error.message}`);
  }

  return { messageId: result.data.messageId };
}
```

The SDK resolves AWS credentials from your environment — the same chain the AWS CLI uses. Your agent never sees an API key; it calls a function.

## Step 4: Give Your AI Editor Wraps Docs

Add Context7 to your MCP config so Claude Code, Cursor, Windsurf, or any MCP-compatible editor can pull the latest Wraps docs into context:

```json
{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp@latest"]
    }
  }
}
```

Full setup at [Context7 Guide](https://wraps.dev/docs/guides/context7).

## Step 5: Give Your Agent Live Access with the Wraps MCP Server

Context7 gives your editor the docs; `@wraps.dev/mcp` gives your agent the infrastructure itself. It exposes your send history, delivery events, domain status, and suppression list as MCP tools — plus guarded sending, disabled by default:

```json
{
  "mcpServers": {
    "wraps": {
      "command": "npx",
      "args": ["-y", "@wraps.dev/mcp"],
      "env": {
        "AWS_REGION": "us-east-1"
      }
    }
  }
}
```

Set `AWS_REGION` to the region your Wraps stack is deployed in. The server reads it from its own environment (`AWS_REGION` or `AWS_DEFAULT_REGION`), never from your AWS config file, and exits on startup without one.

Tools, configuration, and write-mode guardrails: [MCP Server Reference](https://wraps.dev/docs/mcp-reference).

## Next Steps

- [MCP Server Reference](https://wraps.dev/docs/mcp-reference) — give your agent live access to your email infrastructure
- [Email SDK Reference](https://wraps.dev/docs/sdk-reference) — every method and response shape
- [CLI Reference](https://wraps.dev/docs/cli-reference/email) — manage infrastructure
