Office 365 Email MCP
Enables AI agents to send emails via Microsoft 365/Office 365 using app-only authentication and Microsoft Graph API, supporting HTML content, attachments, and CC/BCC.
README
Office 365 Email MCP
An MCP server that lets an AI agent send email through Microsoft 365 / Office 365 using the OAuth2 client-credentials (app-only) flow and the Microsoft Graph API.
No interactive login at runtime — register an app once, grant it Mail.Send, and the server sends mail headlessly. Ideal for automation, notifications, and agent workflows.
Features
office365_send_email— send plain-text or HTML email, with CC/BCC and local file attachments.office365_test_connection— verify your OAuth2 config by acquiring a token (sends nothing).- App-only auth (no user sign-in), tokens cached and refreshed automatically by MSAL.
- Clear, actionable error messages for the common auth/permission/mailbox mistakes.
How it works
agent → MCP tool → MSAL (client credentials) → Entra ID → access token
→ POST https://graph.microsoft.com/v1.0/users/{sender}/sendMail
Prerequisites
- Python 3.10+
- A Microsoft 365 tenant where you can register an app (or an admin who can).
- A licensed mailbox to send from.
1. Register the app in Microsoft Entra ID
- Go to Entra admin center → Identity → Applications → App registrations → New registration.
- Name it (e.g.
office365-email-mcp), leave redirect URI blank, Register. - Copy the Application (client) ID and Directory (tenant) ID from the Overview page.
- Certificates & secrets → New client secret → copy the secret Value (shown once).
- API permissions → Add a permission → Microsoft Graph → Application permissions →
Mail.Send→ Add. - Click Grant admin consent for your tenant. (Requires an admin; the green check must appear.)
Scope it down (recommended).
Mail.Send(Application) lets the app send as any mailbox in the tenant. Restrict it to specific mailboxes with an Application Access Policy in Exchange Online:New-ApplicationAccessPolicy -AppId <CLIENT_ID> ` -PolicyScopeGroupId mcp-senders@yourdomain.com ` -AccessRight RestrictAccess ` -Description "Restrict office365-email-mcp to the mcp-senders group"
2. Install
# from a clone of this repo
pip install .
# or run without installing, using uv
uvx --from . office365-email-mcp
3. Configure
Set these environment variables (see .env.example):
| Variable | Required | Description |
|---|---|---|
O365_TENANT_ID |
yes | Directory (tenant) ID |
O365_CLIENT_ID |
yes | Application (client) ID |
O365_CLIENT_SECRET |
yes | Client secret value |
O365_SENDER |
no | Default sender mailbox (overridable per call) |
4. Add to your MCP client
Claude Desktop / Claude Code (claude_desktop_config.json or .mcp.json):
{
"mcpServers": {
"office365-email": {
"command": "office365-email-mcp",
"env": {
"O365_TENANT_ID": "00000000-0000-0000-0000-000000000000",
"O365_CLIENT_ID": "00000000-0000-0000-0000-000000000000",
"O365_CLIENT_SECRET": "your-secret-value",
"O365_SENDER": "noreply@yourdomain.com"
}
}
}
}
If you didn't pip install, use "command": "uvx" with "args": ["--from", "/path/to/repo", "office365-email-mcp"].
Tools
office365_send_email
| Parameter | Type | Required | Notes |
|---|---|---|---|
to |
string[] | yes | Primary recipients |
subject |
string | yes | |
body |
string | yes | Plain text or HTML |
is_html |
bool | no | Treat body as HTML (default false) |
cc / bcc |
string[] | no | |
sender |
string | no | Overrides O365_SENDER |
attachments |
string[] | no | Local file paths, < ~3 MB total |
save_to_sent_items |
bool | no | Default true |
office365_test_connection
No parameters. Acquires a token and reports success/failure — run this first when troubleshooting.
Troubleshooting
| Error | Fix |
|---|---|
401 Authentication failed |
Client secret expired or wrong tenant/client ID. |
403 Permission denied |
Missing Mail.Send Application permission or admin consent not granted. |
404 Sender mailbox not found |
sender isn't a real, licensed mailbox in the tenant. |
Application Access Policy blocks send |
The sender isn't in the allowed group from your access policy. |
Security notes
- The client secret is a credential — keep it out of source control (
.envis gitignored). Rotate it periodically. - Prefer an Application Access Policy so the app can only send as intended mailboxes.
- Attachments over ~3 MB exceed Graph's single-request
sendMaillimit; share a link instead.
License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。