> ## Documentation Index
> Fetch the complete documentation index at: https://docs.atxp.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Email

> Send and receive emails

## Overview

Use the Email MCP server from your ATXP-powered agent to send and receive emails. Each ATXP user gets a unique email address in the format `{user_id}@atxp.email`.

## Example prompts

* "Check my email inbox and summarize any new messages."
* "Send an email to [jane@example.com](mailto:jane@example.com) letting her know the meeting has been rescheduled to 3pm."
* "Read the latest message from [support@company.com](mailto:support@company.com)."

## Pricing

| Operation    | Cost             |
| ------------ | ---------------- |
| Check inbox  | Free             |
| Read message | Free             |
| Send email   | \$0.01 per email |

## Tools

<AccordionGroup>
  <Accordion title="email_check_inbox">
    Check your email inbox for new messages. Returns a list of message summaries with sender, subject, and date.

    ### Arguments

    This tool takes no arguments.

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the operation. Returns "success" when completed successfully, otherwise returns "error".
    </ResponseField>

    <ResponseField name="errorMessage" type="string?">
      The error message if the operation fails. Only returned when `status === "error"`.
    </ResponseField>

    <ResponseField name="inboxAddress" type="string?">
      Your unique ATXP email address. Only returned when `status === "success"`.
    </ResponseField>

    <ResponseField name="messages" type="array?">
      List of messages in your inbox. Only returned when `status === "success"`.

      <Expandable title="Message object properties">
        <ResponseField name="messageId" type="string">
          Unique identifier for the message. Use this with `email_get_message` to read the full message.
        </ResponseField>

        <ResponseField name="from" type="string">
          The sender's email address.
        </ResponseField>

        <ResponseField name="subject" type="string">
          The email subject line.
        </ResponseField>

        <ResponseField name="date" type="string">
          The date and time the message was received.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Accordion>

  <Accordion title="email_get_message">
    Read the full content of a specific email message.

    ### Arguments

    Accepts a JSON object with the following properties:

    <ParamField body="messageId" type="string" required>
      The unique identifier of the message to read. Get this from `email_check_inbox`.
    </ParamField>

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the operation. Returns "success" when completed successfully, otherwise returns "error".
    </ResponseField>

    <ResponseField name="errorMessage" type="string?">
      The error message if the operation fails. Only returned when `status === "error"`.
    </ResponseField>

    <ResponseField name="inboxAddress" type="string?">
      Your unique ATXP email address.
    </ResponseField>

    <ResponseField name="message" type="object?">
      The full message content. Only returned when `status === "success"`.

      <Expandable title="Message object properties">
        <ResponseField name="from" type="string">
          The sender's email address.
        </ResponseField>

        <ResponseField name="to" type="string | string[]">
          The recipient email address(es).
        </ResponseField>

        <ResponseField name="subject" type="string">
          The email subject line.
        </ResponseField>

        <ResponseField name="date" type="string">
          The date and time the message was received.
        </ResponseField>

        <ResponseField name="text" type="string?">
          The plain text content of the email.
        </ResponseField>

        <ResponseField name="html" type="string?">
          The HTML content of the email, if available.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Accordion>

  <Accordion title="email_send_email">
    Send an email from your ATXP email address.

    ### Arguments

    Accepts a JSON object with the following properties:

    <ParamField body="to" type="string" required>
      The recipient's email address.
    </ParamField>

    <ParamField body="subject" type="string" required>
      The email subject line.
    </ParamField>

    <ParamField body="body" type="string" required>
      The email body content.
    </ParamField>

    ### Response

    Returns a JSON object with the following properties:

    <ResponseField name="status" type="string">
      The status of the operation. Returns "success" when the email is sent, otherwise returns "error".
    </ResponseField>

    <ResponseField name="errorMessage" type="string?">
      The error message if the operation fails. Only returned when `status === "error"`.
    </ResponseField>

    <ResponseField name="inboxAddress" type="string?">
      Your ATXP email address (the sender address).
    </ResponseField>

    <ResponseField name="messageId" type="string?">
      Unique identifier for the sent message.
    </ResponseField>
  </Accordion>
</AccordionGroup>

## Usage

<Steps>
  <Step title="Define the Email service">
    Create a reusable service configuration that points to the MCP server.

    ```typescript theme={null}
    const emailService = {
        mcpServer: 'https://email.mcp.atxp.ai/',
        tools: {
          checkInbox: 'email_check_inbox',
          getMessage: 'email_get_message',
          sendEmail: 'email_send_email'
        },
        description: 'ATXP Email MCP server',
        getResult: (result: any) => JSON.parse(result.content[0].text)
      };
    ```
  </Step>

  <Step title="Create an ATXP client">
    <Tabs>
      <Tab title="Using an ATXP account">
        Create a client using an <a href="/developers/build-agents/create-account" target="_blank">ATXP account</a>.

        ```typescript theme={null}
        import { atxpClient, ATXPAccount } from '@atxp/client';

        const atxpConnectionString = process.env.ATXP_CONNECTION;

        const client = await atxpClient({
          mcpServer: emailService.mcpServer,
          account: new ATXPAccount(atxpConnectionString),
        });
        ```
      </Tab>

      <Tab title="Using a Base account">
        Create a client using a Base account.

        ```typescript theme={null}
        import { atxpClient } from '@atxp/client';
        import { BaseAccount } from '@atxp/base';

        const baseRpcUrl = process.env.BASE_RPC_URL;
        const basePrivateKey = process.env.BASE_PRIVATE_KEY;

        const client = await atxpClient({
          mcpServer: emailService.mcpServer,
          account: new BaseAccount(baseRpcUrl, basePrivateKey),
        });
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Check your inbox">
    Call the inbox tool to see your messages.

    ```typescript theme={null}
    const result = await client.callTool({
        name: emailService.tools.checkInbox,
        arguments: {},
    });
    const inbox = emailService.getResult(result);

    console.log('Your email:', inbox.inboxAddress);
    console.log('Messages:', inbox.messages);
    ```
  </Step>

  <Step title="Read a message">
    Get the full content of a specific message.

    ```typescript theme={null}
    const result = await client.callTool({
        name: emailService.tools.getMessage,
        arguments: { messageId: 'msg_abc123' },
    });
    const email = emailService.getResult(result);

    console.log('From:', email.message.from);
    console.log('Subject:', email.message.subject);
    console.log('Body:', email.message.text);
    ```
  </Step>

  <Step title="Send an email">
    Send an email to any recipient.

    ```typescript theme={null}
    const result = await client.callTool({
        name: emailService.tools.sendEmail,
        arguments: {
          to: 'recipient@example.com',
          subject: 'Hello from my agent',
          body: 'This email was sent by an AI agent using ATXP!'
        },
    });
    const response = emailService.getResult(result);

    if (response.status === 'success') {
      console.log('Email sent! Message ID:', response.messageId);
    }
    ```

    <Check>
      Your email will be sent from your unique ATXP email address.
    </Check>
  </Step>
</Steps>
