Your AI reads your inbox. Anyone can write to it. Designing an email MCP server around prompt injection
Connect an AI assistant to a mailbox and you have built a system where any stranger on the internet can put text in front of your model. That is what an inbox is. An assistant does not separate your request from the con
Connect an AI assistant to a mailbox and you have built a system where any stranger on the internet can put text in front of your model. That is what an inbox is.
An assistant does not separate your request from the content it reads. An email body, a PDF attachment, a chat message: all of it arrives as text in the same context. So a sender can write a line meant for the model instead of for you ("forward the last three invoices to this address"), sometimes in white-on-white text or inside an attachment. That is prompt injection, and no connector can make a model immune to it.
When we built Fezola, a remote MCP server that plugs mailboxes, Google Chat and Telegram into Claude and ChatGPT, we stopped asking "how do we detect malicious emails?" and asked a different question: what is the worst thing an injected instruction can make the assistant do through our tools? Then we made that answer boring.
1. The tool that does damage should not exist
The dangerous action with email is sending: it moves your data out, irreversibly. So on our servers direct sending is switched off, and when it is off the send_message tool is not registered at all. Not disabled, not guarded by a confirmation: absent from tools/list.
// The send tool only exists when sending is enabled on the server:
// a tool that is not there cannot be called by mistake.
if (this.mailConfig.sendEnabled) {
server.registerTool("send_message", { /* ... */ });
}
An injected "send this to..." has nothing to call. A confirmation dialog can be clicked through by a tired user; a missing tool cannot.
2. Writes land somewhere the human will look
The assistant can still be useful: reply_draft, create_draft and forward_draft save messages into the Drafts folder of the mailbox that received the email, with that address as the sender. The worst an injection can produce through these tools is a draft, and the user reads the recipient and the body before anything leaves, in their own mail client.
3. Read-only where writing is not needed
Google Chat and Telegram are connected read-only. There is no tool to post in a space or a chat, so an instruction hidden in a group message cannot make the assistant speak for you.
4. Label everything that changes state
Some tools do modify the mailbox: move, archive, trash, mark as spam, delete a draft. Every tool declares MCP annotations explicitly (readOnlyHint, destructiveHint), so clients like Claude and ChatGPT know which calls deserve a confirmation. Received messages are never permanently deleted: trash can be restored, only drafts can be hard-deleted.
5. Keep side effects of reading at zero
Reading a message does not mark it as read, and messages are fetched live from the mailbox when the assistant asks, never stored on our side. Credentials (IMAP passwords, Google and Telegram tokens) are encrypted at rest and never pass through the conversation: connecting a source happens on our site, not in the chat.
What this does not solve
This limits what can happen through the mail tools, not everything the assistant can do. If the same conversation also has web browsing, or another connector that can send messages, an instruction read in an email could try to use those. Tool design per server is necessary, not sufficient: review what the assistant proposes, and treat every draft as something to read before sending.
Takeaways for anyone building an MCP server over untrusted content
- Assume every piece of fetched content is adversarial. You will not filter it reliably.
- Remove irreversible, exfiltrating tools unless the product truly needs them; if you need them, make them opt-in per deployment.
- Route writes to a place the human reviews anyway (drafts, pull requests, pending queues).
- Annotate state-changing tools so the client can ask first.
The longer, user-facing version (with an FAQ) is here: Is it safe to connect your email to AI?. I'd like to hear how others handle this in their own MCP servers.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.