One wrong to argument can turn an AI agent’s successful test run into an email to a real customer. We use a staged plan to test AI agent email sending in a GitHub project, keeping pull-request checks isolated and reserving real delivery for an explicitly gated smoke test.

Test the agent’s tool choice and arguments first, mock the provider for deterministic unit tests, then test MCP discovery and configuration with isolated credentials. Finally, send one message to an allowlisted inbox using live credentials and verify receipt. A mock confirms request handling; only the controlled send checks the full delivery path.

What testing AI agent email sending actually proves

We separate three claims that often get blurred together: the agent made the right decision, the integration submitted the right provider request, and a message reached an inbox we control. Each claim needs a different test. Passing a tool-call assertion does not prove the provider request was valid, and a mocked provider response does not prove delivery.

For example, give the agent a fixed task to send a build notice. Assert that it selected the send tool, addressed qa-inbox@example.test, used the expected subject, and included the build identifier in the body. Then test the provider boundary separately. For MCP, clients discover available tools with tools/list and invoke them with tools/call; tool definitions include an input schema that can be checked before invocation (MCP tools specification).

Our rule is simple: treat a simulated result as evidence about code, not delivery. A real inbox check belongs only in the final layer, where the recipient is controlled and the send is intentional. For more on building reliable request and error boundaries, see our email API guide for developers.

Choose a safe test setup for a GitHub project

Choose the destination according to the claim you need to test. A mock is fastest, a local capture service lets you inspect generated mail, and a dedicated live inbox checks actual receipt.

SetupBest fitWhat it can establish
Mock providerPull-request unit testsRequest fields and handling of simulated success and failure responses; no message is delivered.
MailHogLocal SMTP development and integration checksWhether an application submits a message over SMTP and what the captured message contains. Its documented Docker setup publishes SMTP on 1025 and the UI/API on 8025 (MailHog deployment guide).
Dedicated inboxGated live smoke testWhether a real provider send reaches an inbox your team controls.

For an SMTP-based local test, configure the application to use MailHog and inspect the captured message in its UI or JSON API. MailHog is useful only if the component under test can be configured to send to it; a hosted MCP server may not expose that routing choice. In that case, keep integration checks isolated with test credentials and reserve an allowlisted inbox for the live check.

A Gmail or Microsoft 365/Outlook account is a mailbox, not a documented test sandbox. For Gmail API testing, Google’s Java quickstart uses a Google Cloud project, OAuth consent configuration, and a developer added as a test user (Gmail API quickstart). For Exchange Online SMTP AUTH, Microsoft says the typical port is TCP 587 and recommends disabling SMTP AUTH organization-wide, enabling it only for mailboxes that need it (Microsoft SMTP AUTH guidance).

Test the agent’s email tool before calling a provider

Start by testing the agent as a decision-maker, before any provider client is available. Give it a fixed scenario and assert the exact tool name and arguments. That catches an agent that chooses a search or draft tool when it should send—or chooses the right action but points it at the wrong recipient.

For a send tool, validate a syntactically acceptable address, a non-empty subject, and a non-empty body. Assert the recipient against a fixed test address rather than merely checking that an address exists. When a prompt asks for a draft, assert that the agent does not call the send tool; when it asks to send, check the requested recipient, subject, and content constraints before allowing the call.

The MCP protocol gives a useful test boundary: inspect the server’s tool catalog and input schemas, then verify the name and arguments sent to tools/call. The catalog can vary by client, so test what the connected server actually advertises rather than hard-coding an assumed universal list. Our AI agent email security guide covers why permission and recipient boundaries matter when agents act on email.

Mock the provider in unit tests

Stub the HTTP client or provider SDK at the network boundary. The test should inspect the outgoing recipient, subject, and body, then return a deterministic success object with a fake message ID. Assert that the application maps that result correctly and reports success to the agent. Provider field names differ, so map these assertions to the API you actually use—such as Resend, SendGrid, or Mailgun—rather than treating an illustrative payload as a shared contract.

provider.send = async (message) => {
  expect(message.to).toEqual(["qa@example.test"]);
  expect(message.subject).toBe("Build complete");
  expect(message.text).toContain("commit 4f2a");
  return { id: "msg_test_123" };
};

const result = await sendAgentEmail(message);
expect(result.messageId).toBe("msg_test_123");

Add a replay or dry-run test that proves the provider method was not called at all. Returning a simulated success is not enough if execution can fall through to a live client. We recommend making the provider dependency injectable and failing tests on unexpected network access; the important pass criterion is that the test cannot quietly send outside its stubbed boundary.

Test the MCP connection and provider configuration

An MCP integration test should use a separate client configuration and test project. Check that the client connects, discovers the expected tools and schemas, invokes the intended tool, and handles the result. The MCP versioning specification places server/discover in the versioning section; it describes server protocol versions, capabilities, and identity, while tool discovery and invocation are defined separately (MCP versioning).

We use Volanea’s hosted MCP endpoint, https://api.volanea.com/mcp, with either a project API key as a bearer token or OAuth for compatible clients. The OAuth flow lets a user sign in in a browser and select a project and test or live mode. Volanea documents dynamic client registration, Client ID Metadata Documents, PKCE (S256), refresh tokens, and revocation; its protected-resource metadata is advertised at /.well-known/oauth-protected-resource/mcp (Volanea MCP documentation).

For a test project, use a sk_test_ key to exercise rendering and logging: test keys do not deliver email. Volanea’s tools include send_test_email and check_delivery under Verify, plus setup_domain and create_webhook_endpoint under Deliver. The setup tools let an integration check domain registration and returned DNS records, or webhook registration and its whsec_ signing secret; keep returned secrets out of logs. MCP-created templates, segments, and workflows are idempotent by name, which is useful when an integration test is retried. For an actual inbox check, use a live-mode key and an allowlisted recipient—not a test key.

AgentMail is another useful comparison when the project targets a hosted email MCP server. Its documentation reports 47 tools, plus 2 organization-selection tools for OAuth sessions, and says clients discover the live catalog and schemas. For stdio-only clients, its bridge uses agentmail-mcp and AGENTMAIL_API_KEY; the npm bridge requires Node.js 20 or newer, and the repository also documents a Python route with uvx agentmail-mcp (AgentMail MCP docs, bridge repository). This is a connection option, not a substitute for assertions on your own tool calls.

Add email-agent checks to GitHub Actions

Run deterministic tests on pull requests without provider credentials, then put a real send in a separate manually dispatched job. GitHub’s pull_request event runs by default for opened, synchronize, and reopened; it does not run when the pull request has a merge conflict. Its GITHUB_SHA identifies the merge-branch commit, while github.event.pull_request.head.sha identifies the pull request head (GitHub event documentation).

name: Email agent tests
on:
  pull_request:
  workflow_dispatch:

jobs:
  unit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test

  live-smoke:
    if: github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    environment: email-smoke
    steps:
      - uses: actions/checkout@v4
      - name: Require live credential
        env:
          VOLANEA_API_KEY: ${{ secrets.VOLANEA_API_KEY }}
        run: test -n "$VOLANEA_API_KEY" || (echo "VOLANEA_API_KEY is required" && exit 1)
      - name: Send controlled smoke test
        env:
          VOLANEA_API_KEY: ${{ secrets.VOLANEA_API_KEY }}
          SMOKE_RECIPIENT: ${{ vars.SMOKE_RECIPIENT }}
        run: npm run email:smoke

Configure the email-smoke environment with a reviewer protection rule if a person must approve each live run. The workflow file must exist on the default branch for workflow_dispatch to trigger (GitHub workflow syntax). An unset secret evaluates to an empty string, so the explicit shell check stops the job before the send step; GitHub does not allow secrets to be directly referenced in an if: condition (GitHub secrets guidance). Keep credentials out of pull-request jobs and logs, and do not let an untrusted pull-request value choose the live recipient.

Test failures, retries, and duplicate-send risks

Add failure cases alongside success tests: missing credentials, invalid recipient, rate limits, provider errors, expired OAuth tokens, and transient network failures. Assert what the agent does next. Invalid input should fail before the provider call; missing credentials should stop with a configuration error; an expired token may trigger refresh, but refreshing authentication must not replay a message that may already have been accepted.

For SMTP/IMAP integrations, test connection and authentication failures separately from message-content validation. Microsoft documents SMTP AUTH with OAuth modern authentication as well as basic authentication. For Gmail, Google recommends “Sign in with Google” rather than app passwords; an app password is a 16-digit passcode and requires 2-Step Verification (Gmail app-password guidance). For a personal Gmail account, Google says a sending-limit error may occur after more than 500 recipients in one email and/or more than 500 emails in a day, with sending potentially resuming within 1 to 24 hours (Gmail sending limits). That makes rate-limit handling a stop-and-report test, not a cue to retry aggressively.

The key duplicate-send case is an ambiguous timeout after submission. If the provider may have accepted the message, the agent should stop and check status or request human review rather than blindly resend. With Volanea, use check_delivery after the live send to inspect delivery status, then independently confirm the message in the controlled inbox. Keep both assertions: a status lookup and inbox receipt answer different questions. Do not infer send idempotency from the documented idempotency of named templates, segments, or workflows.

Run a controlled end-to-end email smoke test

We run this only after mocked and MCP integration checks pass. The live smoke test is a short, bounded proof of the configured path—not a load test or a substitute for unit assertions.

  1. Allowlist one recipient. Use an inbox the team controls, store the address in protected workflow configuration, and reject any recipient outside the allowlist.
  2. Make the run identifiable. Use a subject such as email-smoke-${GITHUB_RUN_ID} and a harmless body containing the build identifier. Assert recipient, subject, and body before the send.
  3. Use live mode for receipt. A Volanea sk_test_ key renders and logs but never delivers. Use a live-mode key for the inbox-verification run; alternatively, use another provider’s controlled live destination.
  4. Capture and verify. Save the tool/provider result and message ID, call Volanea’s check_delivery, then confirm the expected message reached the allowlisted inbox. Treat these as distinct checks rather than assuming one proves the other.
  5. Clean up. Label or remove the message as test data, and rotate credentials if they were exposed during debugging.

This gives a GitHub project repeatable pull-request checks and one deliberate route to real delivery. If you want to run the same workflow with transactional email, campaigns, and automations through one API, start free with 1,000 emails a month.