Connect Mailgun to Claude Code

Send transactional email, and read Mailgun domains, events, stats, suppressions, mailing lists and templates. Add Toolspoke to Claude Code once and it can use 18 Mailgun actions. Your Mailgun credential stays in Toolspoke, and you choose which actions Claude Code may call.

Set it up in Claude Code

Three steps, the first one once for every toolkit you will ever add.

  1. Add Toolspoke to Claude Code

    Run it in your project, then /mcp to sign in

    claude mcp add --transport http toolspoke https://toolspoke.com/mcp

    The sign-in opens in your browser, and Toolspoke asks you to approve it.

  2. Install Mailgun and connect it

    Add Mailgun to a project in your Toolspoke workspace.

    API key. You provide it once, when you install the connector. Toolspoke encrypts it at rest and decrypts it only for the length of a single call, and the gateway attaches it to the outbound request itself, so it is never part of the arguments an agent sends.

    API key, with the username api in front of it
    Paste it in exactly that form: the word api, a colon, then your key. Mailgun reads this as HTTP Basic with the username api. Create the key in Mailgun → your name (top right) → API Security → Add new key. Use an account API key, not a domain sending key: a sending key can only send, so every read here would fail with it.
    API region URL
    Leave blank for a US account. For an EU account use https://api.eu.mailgun.net. The region is shown next to each domain under Send → Sending → Domains. A key sent to the wrong region is rejected as if it were invalid.
  3. Choose what Claude Code may do

    All 18 actions start on. Switch off any of the 5 actions that change something in Mailgun, and Claude Code gets a refusal if it tries.

What you can ask Claude Code for

A few of the Mailgun actions that only read, so they are safe to try first.

  • List the sending domains on this account, with their state (active, unverified, disabled) and type
  • Search the event log for a domain, accepted, delivered, failed, opened, clicked, unsubscribed, complained
  • Retrieve a stored message, its headers and body, by the storage key found in an event's storage.key
  • List addresses on a domain's bounce suppression list, with the error code and message for each

What Claude Code can do in Mailgun

13 actions read, 2 write and 3 delete or permanently change something.

Reads

  • List domains

    List the sending domains on this account, with their state (active, unverified, disabled) and type. The domain names here are what every other action takes. Takes no required arguments, which is why an install tests itself with it.

  • Get domain

    Fetch one domain with its settings and the DNS records Mailgun expects (SPF, DKIM, MX, tracking CNAME), each with its verification state. This is the answer to most "why is mail from this domain failing" questions.

  • List events

    Search the event log for a domain, accepted, delivered, failed, opened, clicked, unsubscribed, complained. Each event carries the recipient, the message headers and, for failures, the reason. Use it to trace what happened to one message or one recipient.

  • Get stored message

    Retrieve a stored message, its headers and body, by the storage key found in an event's storage.key. Mailgun keeps messages for a few days only.

  • Get domain stats

    Counts of one event type for a domain over time, accepted, delivered, failed, opened, clicked, unsubscribed, complained or stored, bucketed by hour, day or month. Use it for delivery and engagement rates.

  • List bounces

    List addresses on a domain's bounce suppression list, with the error code and message for each. Mailgun will not send to these addresses until they are removed.

  • List unsubscribes

    List addresses that have unsubscribed from a domain, with the tags they unsubscribed from (* means everything).

  • List complaints

    List addresses that marked a domain's mail as spam. Mailgun will not send to them.

  • List mailing lists

    List the account's mailing lists, with each list's address, name, access level and member count. The list address is what the member actions take.

  • List list members

    List the members of one mailing list, with name, subscription state and custom variables.

  • List templates

    List the stored templates on a domain, by name, description and creation date. A template name is what send_message's template input takes.

  • Get template

    Fetch one stored template with its active version's content, so you can see which variables it expects before sending with it.

  • Validate address

    Check whether one email address is deliverable, syntax, domain, mailbox and risk, before sending to it. Mailgun bills each validation, and the plan must include the Validate product.

Writes

  • Add unsubscribe

    Add an address to a domain's unsubscribe list, so Mailgun stops sending to it, for every message, or only for one tag. Use it to honour an opt-out that arrived outside Mailgun.

  • Add list member

    Add one member to a mailing list, or update them if upsert is yes. This adds a contact; it sends nothing.

Deletes or permanently changes

  • Send message

    Send one email from a verified Mailgun domain. Classified destructive: it delivers to real inboxes, it cannot be recalled once accepted, and Mailgun bills per message. Supply text, html, or a stored template. Returns the message id and a queued status.

  • Delete bounce

    Remove one address from a domain's bounce list, so Mailgun will send to it again. Destructive because the bounce record is lost and the next send goes out to an address that already failed, which can hurt the domain's reputation.

  • Delete unsubscribe

    Remove an address from a domain's unsubscribe list, so Mailgun will send to it again. Destructive because it overrides a person's opt-out; do it only when they have asked to be subscribed again.

Mailgun in Claude Code: questions

Does Claude Code see my Mailgun credential?

No. The credential is stored encrypted in Toolspoke, and the gateway adds it to each call. Claude Code only ever talks to Toolspoke, and the dashboard shows the last four characters of the credential and nothing more.

Can I stop Claude Code from changing things in Mailgun?

Yes. Each of the 18 actions can be switched off for a project. Turn off the 5 that change something and Claude Code can only read.

Will 18 actions crowd Claude Code's context?

No. Toolspoke shows Claude Code five bridge tools, plus a guide where a toolkit has one, and Claude Code searches for the Mailgun action it needs when it needs it. Adding more toolkits does not add more tools to its list.

Can I add it once for every project?

Yes. Add --scope user to the command and Claude Code keeps Toolspoke in every project on this machine. Without it, the server is added to the project you ran the command in.

What does it cost?

Tool calls are free on every plan, and a Mailgun call does not run in a sandbox, so it bills nothing.

Try Mailgun in Claude Code

Free to start, and tool calls cost nothing on any plan.