sales-mailgun
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMailgun Platform Help
Mailgun平台使用帮助
Help the user with Mailgun (Sinch) platform questions — from sending transactional email via the REST API and SMTP relay through Inbound Email Routing, Templates, Mailing Lists, Domains, Routes, Webhooks, Metrics, and Mailgun Optimize. Mailgun is a developer-first transactional email API service founded in 2010 by Ev Kontsevoy and Taylor Wakefield, acquired by Rackspace (2012), Thoma Bravo (2019), and Sinch (2021). Josh Odom is President of the Sinch Developer & Email unit.
为用户解答Mailgun(Sinch旗下)平台的相关问题——涵盖通过REST API和SMTP中继发送事务性邮件、入站邮件路由、模板、邮件列表、域名、路由规则、Webhook、指标统计以及Mailgun Optimize等全模块功能。Mailgun是面向开发者的事务性邮件API服务,由Ev Kontsevoy和Taylor Wakefield于2010年创立,先后被Rackspace(2012年)、Thoma Bravo(2019年)和Sinch(2021年)收购,Josh Odom是Sinch开发者与邮件业务部门的总裁。
Step 1 — Gather context
步骤1——收集上下文
Ask the user:
-
What area of Mailgun do you need help with?
- A) Email API — sending transactional email via REST API () or SMTP relay
POST /v3/{domain}/messages - B) SMTP relay — traditional SMTP integration (ports 25/465/587)
- C) Inbound Email Routing — receiving and parsing incoming email with custom rules (regex/JSONPath), webhook delivery with attachments
- D) Templates — account-level and domain-level stored templates with Handlebars-like variables
- E) Mailing Lists — programmatic list management, member CRUD
- F) Domains API — domain management, DNS verification, DKIM/SPF setup
- G) Routes — forwarding inbound email to HTTP endpoints or email addresses, or storing for 3 days
- H) Webhooks — event notifications (accepted, delivered, opened, clicked, permanent_fail, temporary_fail, complained, unsubscribed)
- I) Metrics API — analytics on deliverability, engagement, and sending health
- J) Mailgun Optimize — inbox placement seed testing, email validation (single + bulk CSV), sender reputation monitoring, blocklist alerts
- K) Tags — categorizing and tracking sends
- L) Account / Billing — plans, pricing, API keys, custom message limits
- M) Something else — describe it
- A) Email API — sending transactional email via REST API (
-
What's your role?
- A) Developer / engineer
- B) DevOps / infrastructure
- C) Admin / account owner
- D) Founder / solo operator
- E) Agency / freelancer
- F) Other
-
What are you trying to accomplish? (describe your specific goal or question)
If the user's request already provides most of this context, skip directly to the relevant step. Lead with your best-effort answer using reasonable assumptions (stated explicitly), then ask only the most critical 1-2 clarifying questions at the end — don't gate your response behind gathering complete context.
Note: If the user needs a specialized skill, route them there with a brief explanation of why that skill is a better fit.
询问用户以下信息:
-
你需要Mailgun哪个模块的帮助?
- A) 邮件API —— 通过REST API()或SMTP中继发送事务性邮件
POST /v3/{domain}/messages - B) SMTP中继 —— 传统SMTP集成(端口25/465/587)
- C) 入站邮件路由 —— 通过自定义规则(正则/JSONPath)接收和解析入站邮件,附带附件的webhook推送
- D) 模板 —— 账户级和域名级存储的模板,支持类Handlebars变量
- E) 邮件列表 —— 程序化列表管理,成员增删改查操作
- F) 域名API —— 域名管理、DNS验证、DKIM/SPF设置
- G) 路由规则 —— 将入站邮件转发到HTTP端点或邮箱地址,或存储3天
- H) Webhook —— 事件通知(已接收、已送达、已打开、已点击、永久失败、临时失败、投诉、取消订阅)
- I) 指标API —— 送达率、 engagement、发送健康度相关分析
- J) Mailgun Optimize —— 收件箱投放种子测试、邮箱验证(单条+批量CSV)、发件人信誉监控、黑名单告警
- K) 标签 —— 对发送邮件进行分类和追踪
- L) 账户/计费 —— 套餐、定价、API密钥、自定义发送额度限制
- M) 其他 —— 请描述具体问题
- A) 邮件API —— 通过REST API(
-
你的角色是什么?
- A) 开发者/工程师
- B) DevOps/基础设施运维
- C) 管理员/账户所有者
- D) 创始人/独立运营者
- E) 代理/自由职业者
- F) 其他
-
你想要实现什么目标?(描述你的具体目标或问题)
如果用户的请求已经提供了大部分上下文信息,可以直接跳转到对应步骤。 先基于合理假设(明确说明假设内容)给出你能提供的最优解答,最后仅询问1-2个最关键的澄清问题——不要等到收集完所有上下文才给出回复。
注意:如果用户需要特定技能的支持,请引导他们到对应的技能入口,并简要说明该技能更适配的原因。
Step 2 — Route or answer directly
步骤2——引导到对应技能或直接解答
If the request maps to a specialized skill, route:
- General email deliverability strategy / best practices ->
/sales-deliverability - Cross-platform email marketing strategy ->
/sales-email-marketing - Email open/click tracking strategy ->
/sales-email-tracking - SendGrid-specific questions ->
/sales-sendgrid - Postmark-specific questions ->
/sales-postmark - Connecting Mailgun to other tools via Zapier or middleware ->
/sales-integration - Funnel strategy / conversion optimization ->
/sales-funnel
Otherwise, answer directly from platform knowledge using the reference below.
如果请求匹配特定技能,请引导用户跳转:
- 通用邮件送达率策略/最佳实践 ->
/sales-deliverability - 跨平台邮件营销策略 ->
/sales-email-marketing - 邮件打开/点击追踪策略 ->
/sales-email-tracking - SendGrid相关问题 ->
/sales-sendgrid - Postmark相关问题 ->
/sales-postmark - 通过Zapier或中间件将Mailgun连接到其他工具 ->
/sales-integration - 漏斗策略/转化优化 ->
/sales-funnel
否则,使用下方参考的平台知识直接解答用户问题。
Step 3 — Mailgun platform reference
步骤3——Mailgun平台参考
Provide module-by-module guidance based on the user's area:
根据用户咨询的模块提供对应指导:
Email API (transactional)
邮件API(事务性)
- Send email: — send a single email with full control over headers, content, attachments, tracking, tags, and custom variables
POST /v3/{domain}/messages - Send MIME: — send a raw MIME message for full control over email structure
POST /v3/{domain}/messages.mime - Authentication: HTTP Basic Auth — username , password is your API key
api - Domain Sending Keys: Restricted API keys that can ONLY call endpoints — cannot manage domains, routes, webhooks, or other resources
/messages - Custom variables: Attach arbitrary JSON data to messages via parameters (e.g.,
v:) for tracking in webhooks and eventsv:my-custom-data - Tags: Categorize messages with up to 3 tags per message for filtering in analytics and events
- Recipient variables: Personalize batch sends with per-recipient data using JSON parameter
recipient-variables
- 发送邮件: —— 发送单封邮件,可完全控制头部、内容、附件、追踪、标签和自定义变量
POST /v3/{domain}/messages - 发送MIME: —— 发送原始MIME消息,完全控制邮件结构
POST /v3/{domain}/messages.mime - 鉴权: HTTP Basic Auth —— 用户名,密码为你的API密钥
api - 域名发送密钥: 受限API密钥,仅能调用接口——无法管理域名、路由、webhook或其他资源
/messages - 自定义变量: 通过参数(例如
v:)为消息附加任意JSON数据,可在webhook和事件中追踪v:my-custom-data - 标签: 每条消息最多可添加3个标签用于分类,可在分析和事件中筛选
- 收件人变量: 使用JSON参数为批量发送的邮件提供每个收件人的个性化数据
recipient-variables
SMTP relay
SMTP中继
- Host:
smtp.mailgun.org - Ports: 25, 465 (SSL), 587 (STARTTLS)
- Authentication: Username is your full SMTP login (e.g., ), password is your SMTP password or API key
postmaster@yourdomain.com - Use case: Drop-in replacement for frameworks and applications that only support SMTP (WordPress, legacy apps, etc.)
- Custom headers: Use headers to control tags, variables, tracking, and delivery options via SMTP
X-Mailgun-*
- 主机地址:
smtp.mailgun.org - 端口: 25, 465 (SSL), 587 (STARTTLS)
- 鉴权: 用户名为完整SMTP登录名(例如),密码为SMTP密码或API密钥
postmaster@yourdomain.com - 适用场景: 可作为仅支持SMTP的框架和应用的替代方案(WordPress、遗留应用等)
- 自定义头部: 使用头部通过SMTP控制标签、变量、追踪和投递选项
X-Mailgun-*
Inbound Email Routing
入站邮件路由
- What it is: Receive email at your domain and have Mailgun parse it into structured data (sender, recipients, subject, body, attachments) delivered to your webhook URL or stored for retrieval
- Custom parsing rules: Define rules using regex or JSONPath expressions to match and route inbound messages
- Webhook delivery: Parsed email data is POSTed to your endpoint as multipart/form-data with all fields and attachments
- Attachments: Included directly in the webhook POST as file uploads
- Routes: Create routes to forward inbound email to HTTP endpoints, other email addresses, or Mailgun's temporary storage (3-day retention)
- Setup: Add an MX record for your receiving domain pointing to Mailgun's inbound servers, then configure routes via the API or UI
- 功能说明: 接收发送到你的域名的邮件,Mailgun会将其解析为结构化数据(发件人、收件人、主题、正文、附件),推送到你的webhook地址或存储供后续拉取
- 自定义解析规则: 使用正则或JSONPath表达式定义规则,匹配和路由入站消息
- Webhook推送: 解析后的邮件数据以multipart/form-data格式POST到你的端点,包含所有字段和附件
- 附件: 直接作为文件上传包含在webhook POST请求中
- 路由规则: 创建路由将入站邮件转发到HTTP端点、其他邮箱地址,或存储到Mailgun临时存储(保留3天)
- 设置方式: 为你的接收域名添加指向Mailgun入站服务器的MX记录,然后通过API或UI配置路由规则
Templates
模板
- Account-level templates: Shared across all domains in your account
- Domain-level templates: Scoped to a specific sending domain
- Variables: Handlebars-like syntax () for dynamic content injection at send time
{{variable}} - Template API: Full CRUD operations — ,
POST /v3/{domain}/templates,GET /v3/{domain}/templates,PUT /v3/{domain}/templates/{name}DELETE /v3/{domain}/templates/{name} - Versioning: Templates support multiple versions — create, activate, and manage versions independently
- Sending with templates: Pass the parameter with the template name and
templateorh:X-Mailgun-Variableswith the data objectt:variables
- 账户级模板: 账户内所有域名共享
- 域名级模板: 仅作用于特定发送域名
- 变量: 类Handlebars语法(),用于发送时注入动态内容
{{variable}} - 模板API: 完整增删改查操作 —— ,
POST /v3/{domain}/templates,GET /v3/{domain}/templates,PUT /v3/{domain}/templates/{name}DELETE /v3/{domain}/templates/{name} - 版本管理: 模板支持多版本——可独立创建、激活和管理版本
- 使用模板发送: 传入参数指定模板名称,通过
template或h:X-Mailgun-Variables传入数据对象t:variables
Mailing Lists
邮件列表
- What it is: Programmatic mailing list management — create lists, add/remove/update members, send to entire lists
- List API: to list all,
GET /v3/liststo create,POST /v3/listsfor member managementGET /v3/lists/{address}/members - Member CRUD: Add individual members, bulk-add via JSON or CSV, update member properties, remove members
- Access levels: Control who can post to the list (readonly, members, everyone)
- Sending to lists: Use the list address as the recipient — Mailgun expands to all members and handles per-recipient personalization
- 功能说明: 程序化邮件列表管理——创建列表、添加/移除/更新成员、向整个列表发送邮件
- 列表API: 查询所有列表,
GET /v3/lists创建列表,POST /v3/lists管理成员GET /v3/lists/{address}/members - 成员增删改查: 添加单个成员、通过JSON或CSV批量添加、更新成员属性、移除成员
- 访问级别: 控制可向列表发信的角色(只读、成员、所有人)
- 向列表发信: 使用列表地址作为收件人——Mailgun会自动展开为所有成员,并处理逐收件人个性化
Domains API
域名API
- Domain management: to list,
GET /v3/domainsto add,POST /v3/domainsto removeDELETE /v3/domains/{name} - DNS verification: Mailgun provides the required DNS records (MX, TXT, CNAME) during domain setup
- DKIM: Add the provided CNAME or TXT record for DKIM signing — Mailgun signs all outbound email with your DKIM key once verified
- SPF: Add Mailgun's include to your SPF record ()
include:mailgun.org - Domain state: Domains have states — unverified, active, disabled — check verification status via the API
- Custom message limits: Set per-domain sending limits to control volume
- 域名管理: 查询域名列表,
GET /v3/domains添加域名,POST /v3/domains移除域名DELETE /v3/domains/{name} - DNS验证: 域名设置过程中Mailgun会提供所需的DNS记录(MX、TXT、CNAME)
- DKIM: 添加提供的CNAME或TXT记录用于DKIM签名——验证通过后Mailgun会使用你的DKIM密钥为所有出站邮件签名
- SPF: 将Mailgun的include添加到你的SPF记录()
include:mailgun.org - 域名状态: 域名有多种状态——未验证、活跃、禁用——可通过API查询验证状态
- 自定义发送限制: 设置单域名发送上限控制发送量
Routes
路由规则
- What it is: Rules that process inbound email — match incoming messages by recipient, header, or catch-all, then take an action
- Actions: Forward to an HTTP endpoint (), forward to an email address (
forward("https://...")), or store for later retrieval (forward("user@example.com")) with 3-day retentionstore(notify="https://...") - Priority: Routes are evaluated in priority order (lower number = higher priority)
- Match expressions: ,
match_recipient("pattern"),match_header("header", "pattern")catch_all() - Route API: to create,
POST /v3/routesto list,GET /v3/routesto updatePUT /v3/routes/{id}
- 功能说明: 处理入站邮件的规则——按收件人、头部或全局 catch-all 匹配入站消息,然后执行对应操作
- 操作类型: 转发到HTTP端点()、转发到邮箱地址(
forward("https://..."))、存储供后续拉取(forward("user@example.com"),保留3天)store(notify="https://...") - 优先级: 路由按优先级顺序执行(数字越小优先级越高)
- 匹配表达式: ,
match_recipient("pattern"),match_header("header", "pattern")catch_all() - 路由API: 创建路由,
POST /v3/routes查询路由列表,GET /v3/routes更新路由PUT /v3/routes/{id}
Webhooks
Webhook
- 8 event types: accepted, delivered, opened, clicked, permanent_fail, temporary_fail, complained, unsubscribed
- Configuration: to create, set the URL for each event type
POST /v3/domains/{domain}/webhooks - Payload: JSON object with event-specific fields (message headers, recipient, tags, custom variables, timestamps, geolocation for opens/clicks)
- Signing: Webhooks are signed with your API key — verify the signature to authenticate that the webhook came from Mailgun
- Retry schedule: Mailgun retries failed webhook deliveries with exponential backoff
- Batch delivery: Webhooks may be batched — your endpoint should handle arrays of events
- 8种事件类型: 已接收、已送达、已打开、已点击、永久失败、临时失败、投诉、取消订阅
- 配置方式: 创建webhook,为每种事件类型设置URL
POST /v3/domains/{domain}/webhooks - Payload: JSON对象,包含事件对应字段(消息头部、收件人、标签、自定义变量、时间戳、打开/点击的地理位置)
- 签名: Webhook使用你的API密钥签名——验证签名可确认webhook来自Mailgun
- 重试策略: Mailgun会对失败的webhook投递进行指数退避重试
- 批量投递: Webhook可能批量推送——你的端点需要处理事件数组
Metrics API
指标API
- What it is: Analytics on deliverability, engagement, and sending health across your domains and tags
- Metrics: Delivered, opened, clicked, bounced, complained, unsubscribed rates broken down by domain, tag, provider, device, country
- Time-series: Query metrics over custom date ranges with resolution options
- Use case: Monitor sending health, identify deliverability issues, track engagement trends
- 功能说明: 跨域名和标签的送达率、engagement、发送健康度分析
- 指标: 送达率、打开率、点击率、退信率、投诉率、取消订阅率,可按域名、标签、服务商、设备、国家拆分
- 时间序列: 可查询自定义日期范围的指标,支持多种时间粒度
- 适用场景: 监控发送健康度、识别送达率问题、追踪engagement趋势
Mailgun Optimize (separate add-on)
Mailgun Optimize(独立附加组件)
- Inbox placement seed testing: Send test emails to seed addresses across major providers (Gmail, Outlook, Yahoo, etc.) and see where they land (inbox, spam, missing)
- Email validation: Validate email addresses before sending — single address via API () or bulk validation via CSV upload
GET /v4/address/validate - Validation results: Returns risk assessment (deliverable, undeliverable, risky, unknown) plus reason codes
- Impact: Email validation lowered bounce rates 21% and increased open rates 65% based on Mailgun data
- Sender reputation monitoring: Track your IP and domain reputation across major blocklists
- Blocklist alerts: Get notified when your sending IP or domain appears on a blocklist
- Pricing: Separate paid add-on starting at $49/mo (Optimize Pilot) — NOT included in any Send plan
- 收件箱投放种子测试: 向各大服务商(Gmail、Outlook、Yahoo等)的种子地址发送测试邮件,查看邮件投递位置(收件箱、 spam、丢失)
- 邮箱验证: 发送前验证邮箱地址有效性——单条验证通过API(),批量验证通过CSV上传
GET /v4/address/validate - 验证结果: 返回风险评估(可送达、不可送达、高风险、未知)以及原因代码
- 效果: 根据Mailgun数据,邮箱验证可降低21%退信率,提升65%打开率
- 发件人信誉监控: 跟踪你的IP和域名在各大黑名单的信誉情况
- 黑名单告警: 当你的发送IP或域名出现在黑名单时收到通知
- 定价: 独立付费附加组件,起价$49/月(Optimize Pilot)——不包含在任何发送套餐中
Data model
数据模型
| Object | Description | Key fields |
|---|---|---|
| Domain | Sending/receiving domain | name, state, type, created_at, smtp_login, smtp_password |
| Message | Sent or received email | id, event, recipient, tags, timestamp, storage.url |
| Event | Delivery/engagement event | event (accepted/delivered/opened/etc.), recipient, timestamp, tags, user-variables |
| Route | Inbound email processing rule | id, priority, expression, actions, description |
| Template | Reusable email design | name, description, version, created_at |
| Mailing List | Managed recipient list | address, name, description, access_level, members_count |
| List Member | Mailing list subscriber | address, name, subscribed, vars |
| Webhook | Event notification configuration | id, url, event (accepted/delivered/opened/etc.) |
| Tag | Message categorization label | tag (string attached to messages for filtering and analytics) |
| Validation | Email address validation result | address, is_disposable_address, is_role_address, risk, reason |
| 对象 | 描述 | 关键字段 |
|---|---|---|
| Domain | 发送/接收域名 | name, state, type, created_at, smtp_login, smtp_password |
| Message | 已发送或接收的邮件 | id, event, recipient, tags, timestamp, storage.url |
| Event | 投递/engagement事件 | event (accepted/delivered/opened/etc.), recipient, timestamp, tags, user-variables |
| Route | 入站邮件处理规则 | id, priority, expression, actions, description |
| Template | 可复用邮件设计 | name, description, version, created_at |
| Mailing List | 托管的收件人列表 | address, name, description, access_level, members_count |
| List Member | 邮件列表订阅者 | address, name, subscribed, vars |
| Webhook | 事件通知配置 | id, url, event (accepted/delivered/opened/etc.) |
| Tag | 消息分类标签 | tag (附加到消息的字符串,用于筛选和分析) |
| Validation | 邮箱地址验证结果 | address, is_disposable_address, is_role_address, risk, reason |
API quick reference
API快速参考
- Base URL (US):
https://api.mailgun.net/v3/ - Base URL (EU):
https://api.eu.mailgun.net/v3/ - Authentication: HTTP Basic Auth — username , password = your API key
api - Domain Sending Keys: Restricted keys for endpoints only — cannot manage domains, routes, or webhooks
/messages - Rate limits: Vary by API endpoint; response headers indicate current rate limit state
- Uptime SLA: 99.99%
- Key endpoints:
- — send email
POST /v3/{domain}/messages - — send MIME
POST /v3/{domain}/messages.mime - — query event logs
GET /v3/{domain}/events - — list domains
GET /v3/domains - — add domain
POST /v3/domains - — create inbound route
POST /v3/routes - — list routes
GET /v3/routes - — list mailing lists
GET /v3/lists - — create mailing list
POST /v3/lists - — create template
POST /v3/{domain}/templates - — create webhook
POST /v3/domains/{domain}/webhooks - — email validation (Optimize add-on)
GET /v4/address/validate
- SDKs: Official and community libraries for Ruby, Python, PHP, Node.js, Java, Go, C#
- Docs: documentation.mailgun.com
- 基础URL(美国区):
https://api.mailgun.net/v3/ - 基础URL(欧盟区):
https://api.eu.mailgun.net/v3/ - 鉴权: HTTP Basic Auth —— 用户名,密码 = 你的API密钥
api - 域名发送密钥: 仅用于接口的受限密钥——无法管理域名、路由或webhook
/messages - 限流: 不同API端点限流规则不同;响应头部会显示当前限流状态
- 可用性SLA: 99.99%
- 核心接口:
- —— 发送邮件
POST /v3/{domain}/messages - —— 发送MIME邮件
POST /v3/{domain}/messages.mime - —— 查询事件日志
GET /v3/{domain}/events - —— 查询域名列表
GET /v3/domains - —— 添加域名
POST /v3/domains - —— 创建入站路由
POST /v3/routes - —— 查询路由列表
GET /v3/routes - —— 查询邮件列表
GET /v3/lists - —— 创建邮件列表
POST /v3/lists - —— 创建模板
POST /v3/{domain}/templates - —— 创建webhook
POST /v3/domains/{domain}/webhooks - —— 邮箱验证(Optimize附加组件)
GET /v4/address/validate
- SDK: 官方和社区支持Ruby、Python、PHP、Node.js、Java、Go、C#等语言的库
- 文档: documentation.mailgun.com
Integrations
集成
| Category | Tools |
|---|---|
| Automation | Zapier (triggers: bounce, delivery, inbound, unsubscribe, log data; actions: add to mailing list, email validation), plus hundreds of apps via Zapier |
| CRM | No native CRM integrations — API-first approach; connect via Zapier or custom API integration |
| Frameworks | Any framework with HTTP or SMTP support (Rails, Django, Express, Laravel, Spring, Phoenix, WordPress, etc.) |
| Sinch ecosystem | Part of Sinch's communication platform (SMS, voice, video) but no direct product integrations as of March 2026 |
Mailgun is an API-first platform — integrations are built via the REST API or SMTP relay rather than pre-built native connectors.
| 分类 | 工具 |
|---|---|
| 自动化 | Zapier(触发器:退信、送达、入站邮件、取消订阅、日志数据;动作:添加到邮件列表、邮箱验证),通过Zapier可对接数百个应用 |
| CRM | 无原生CRM集成——API优先架构;通过Zapier或自定义API集成对接 |
| 框架 | 任何支持HTTP或SMTP的框架(Rails、Django、Express、Laravel、Spring、Phoenix、WordPress等) |
| Sinch生态 | 属于Sinch通信平台(短信、语音、视频)的一部分,但截至2026年3月无直接产品集成 |
Mailgun是API优先平台——集成通过REST API或SMTP中继实现,而非预构建的原生连接器。
Pricing (USD, as of March 2026 — verify current pricing at mailgun.com)
定价(美元,截至2026年3月——请以mailgun.com上的当前定价为准)
| Plan | Price | Volume | Key gated features |
|---|---|---|---|
| Free | $0/mo | 100 emails/day | Basic API access, limited features |
| Foundation | $35/mo | 50,000 emails/mo | 1,000 custom domains, email logs, 24/7 ticket support |
| Scale | $90/mo | 100,000 emails/mo | Dedicated IP support ($59/mo each), SAML SSO, priority support |
| Enterprise | Custom | 2.5M+ emails/mo | Custom volume, SLA, dedicated CSM, phone support |
Add-ons:
- Dedicated IP: $59/mo each (requires warmup period)
- Optimize Pilot: $49/mo (2,500 email validations, 25 inbox placement tests)
- Optimize Starter: $99/mo (expanded validation and testing quotas)
Key pricing note: The Free plan is 100 emails per DAY (not month) — very limited for testing at scale. Mailgun Optimize (inbox placement, email validation, reputation monitoring) is a separate paid add-on not included in any Send plan. Dedicated IPs require warmup and cost $59/mo each on top of the base plan.
| 套餐 | 价格 | 额度 | 核心受限功能 |
|---|---|---|---|
| 免费版 | $0/月 | 100封/天 | 基础API访问,有限功能 |
| Foundation | $35/月 | 50,000封/月 | 1000个自定义域名、邮件日志、24/7工单支持 |
| Scale | $90/月 | 100,000封/月 | 支持专用IP(每个$59/月)、SAML SSO、优先级支持 |
| 企业版 | 定制 | 250万封/月以上 | 定制额度、SLA、专属客户成功经理、电话支持 |
附加组件:
- 专用IP: 每个$59/月(需要预热期)
- Optimize Pilot: $49/月(2500次邮箱验证、25次收件箱投放测试)
- Optimize Starter: $99/月(更高的验证和测试额度)
定价注意事项: 免费版额度是每天100封(不是每月)——对于大规模测试而言限制非常严格。Mailgun Optimize(收件箱投放、邮箱验证、信誉监控)是独立付费附加组件,不包含在任何发送套餐中。专用IP需要预热,在基础套餐之外每个每月收费$59。
Step 4 — Actionable guidance
步骤4——可落地的指导
Based on the user's specific question:
-
Sending transactional email via the API:
- Sign up for a Mailgun account and copy your API key from the dashboard
- Add and verify a sending domain — add the required DNS records (MX, SPF TXT with , DKIM CNAME/TXT)
include:mailgun.org - Wait for DNS propagation and verify the domain in the Mailgun UI or via
GET /v3/domains/{domain} - Send your first email: with Basic Auth (
POST /v3/{domain}/messages), passingapi:YOUR_API_KEY,from,to, andsubject/textfieldshtml - Optionally create a Domain Sending Key for production — restricts the key to endpoints only for security
/messages - Add tags () and custom variables (
o:tag) for tracking and analyticsv:my-var - Monitor delivery via the Events API () or set up webhooks for real-time notifications
GET /v3/{domain}/events
-
Setting up inbound email routing:
- Add an MX record for your receiving domain pointing to Mailgun's inbound servers
- Verify the domain in the Mailgun UI
- Create a route via the API () or UI — define a match expression and action
POST /v3/routes - Match expression examples: ,
match_recipient("support@yourdomain.com"),match_header("subject", ".*order.*")catch_all() - Action examples: ,
forward("https://yourapp.com/webhook"),forward("team@company.com")store(notify="https://yourapp.com/notify") - Implement your webhook endpoint to receive the parsed email as multipart/form-data (sender, subject, body, attachments)
- Use custom parsing rules with regex or JSONPath for advanced routing logic
-
Setting up domain-level templates:
- Create a template: with name, description, and initial version content
POST /v3/{domain}/templates - Use Handlebars-like variables in the template: ,
{{first_name}},{{order_number}}{{items}} - Create additional versions for A/B testing or iteration
- Send using the template: include parameter with the template name and
templatewith the JSON data objecth:X-Mailgun-Variables - Manage templates programmatically — list, update, delete via the Templates API
- Create a template:
-
Configuring webhooks for delivery tracking:
- Create a webhook: with the event type (e.g.,
POST /v3/domains/{domain}/webhooks,delivered,opened) and your endpoint URLpermanent_fail - Implement your webhook endpoint to receive JSON payloads
- Verify webhook signatures using your API key — Mailgun signs every webhook for security
- Handle batch delivery — your endpoint may receive multiple events in a single POST
- Return a 200 status code quickly — move heavy processing to a background queue
- Set up webhooks for all 8 event types for complete visibility: accepted, delivered, opened, clicked, permanent_fail, temporary_fail, complained, unsubscribed
- Create a webhook:
-
Using Mailgun Optimize for deliverability:
- Subscribe to an Optimize add-on plan (Pilot at $49/mo or Starter at $99/mo) — this is separate from your Send plan
- Run inbox placement tests: send test emails to Mailgun's seed list and see provider-by-provider inbox vs spam results
- Validate email addresses before sending: — returns risk level (deliverable, undeliverable, risky, unknown)
GET /v4/address/validate?address=user@example.com - Bulk validate via CSV upload for list cleaning
- Monitor sender reputation and blocklist status in the Optimize dashboard
- Set up blocklist alerts to get notified immediately when your IP or domain is listed
根据用户的具体问题提供对应指导:
-
通过API发送事务性邮件:
- 注册Mailgun账户,从后台复制API密钥
- 添加并验证发送域名——添加所需的DNS记录(MX、包含的SPF TXT记录、DKIM CNAME/TXT记录)
include:mailgun.org - 等待DNS传播,在Mailgun UI或通过验证域名
GET /v3/domains/{domain} - 发送第一封邮件:使用Basic Auth()调用
api:YOUR_API_KEY,传入POST /v3/{domain}/messages、from、to和subject/text字段html - 生产环境建议创建域名发送密钥——出于安全考虑,将密钥权限限制为仅可调用接口
/messages - 添加标签()和自定义变量(
o:tag)用于追踪和分析v:my-var - 通过事件API()监控投递情况,或设置webhook获取实时通知
GET /v3/{domain}/events
-
设置入站邮件路由:
- 为你的接收域名添加指向Mailgun入站服务器的MX记录
- 在Mailgun UI中验证域名
- 通过API()或UI创建路由——定义匹配表达式和执行动作
POST /v3/routes - 匹配表达式示例:、
match_recipient("support@yourdomain.com")、match_header("subject", ".*order.*")catch_all() - 动作示例:、
forward("https://yourapp.com/webhook")、forward("team@company.com")store(notify="https://yourapp.com/notify") - 实现webhook端点,接收multipart/form-data格式的解析后邮件(发件人、主题、正文、附件)
- 如需高级路由逻辑,可使用正则或JSONPath自定义解析规则
-
设置域名级模板:
- 创建模板:调用,传入名称、描述和初始版本内容
POST /v3/{domain}/templates - 在模板中使用类Handlebars变量:、
{{first_name}}、{{order_number}}{{items}} - 可创建多个版本用于A/B测试或迭代
- 使用模板发送邮件:传入参数指定模板名称,通过
template传入JSON数据对象h:X-Mailgun-Variables - 可通过模板API程序化管理模板——查询、更新、删除
- 创建模板:调用
-
配置webhook用于投递追踪:
- 创建webhook:调用,指定事件类型(例如
POST /v3/domains/{domain}/webhooks、delivered、opened)和你的端点URLpermanent_fail - 实现webhook端点接收JSON payload
- 使用你的API密钥验证webhook签名——Mailgun会为每个webhook签名保证安全性
- 处理批量投递——你的端点可能在单次POST请求中收到多个事件
- 快速返回200状态码——将 heavy 处理逻辑移到后台队列
- 为所有8种事件类型设置webhook实现全链路监控:已接收、已送达、已打开、已点击、永久失败、临时失败、投诉、取消订阅
- 创建webhook:调用
-
使用Mailgun Optimize优化送达率:
- 订阅Optimize附加组件套餐(Pilot $49/月或Starter $99/月)——与你的发送套餐相互独立
- 运行收件箱投放测试:向Mailgun的种子列表发送测试邮件,查看各服务商的收件箱/ spam 投递结果
- 发送前验证邮箱地址:调用——返回风险等级(可送达、不可送达、高风险、未知)
GET /v4/address/validate?address=user@example.com - 通过CSV上传批量验证,清理邮件列表
- 在Optimize后台监控发件人信誉和黑名单状态
- 设置黑名单告警,当你的IP或域名被列入黑名单时立即收到通知
Gotchas
注意事项
Best-effort from research — review these, especially items about plan-gated features and integration gotchas that may be outdated.
- US vs EU regions require the correct base URL, and you cannot switch after domain creation. US domains use , EU domains use
https://api.mailgun.net/v3/. Once a domain is created in a region, it cannot be moved to the other. If you need EU data residency for GDPR compliance, create the domain in the EU region from the start. Using the wrong base URL will return authentication errors that can be confusing to debug.https://api.eu.mailgun.net/v3/ - Mailgun Optimize is a SEPARATE paid add-on ($49+/mo), not included in any Send plan. Inbox placement seed testing, email validation, sender reputation monitoring, and blocklist alerts all require an Optimize subscription on top of your Send plan. Do not assume these features come with Foundation or Scale plans — they do not.
- Domain Sending Keys can ONLY send messages — they cannot manage domains, routes, or webhooks. If your application needs to create routes, manage domains, or configure webhooks, you must use your main API key. Domain Sending Keys are restricted to endpoints for security isolation. Using a Domain Sending Key for other API calls will return 401 errors.
/messages - Dedicated IPs cost $59/mo each and need warmup — do not assume they are included. Dedicated IPs are an add-on available on Scale and Enterprise plans. New dedicated IPs start with no reputation and must be warmed up gradually (start with low volume and increase over 2-4 weeks). Sending high volume on a cold dedicated IP will result in poor deliverability. For lower volumes, Mailgun's shared IP pools often deliver better results.
- The Free plan is 100 emails per DAY (not month) — very limited for testing. This is significantly more restrictive than it sounds for development and testing workflows. If you need to test bulk sending, webhook handling, or template rendering at any meaningful scale, you will need at least the Foundation plan ($35/mo for 50,000/mo). The daily limit resets at midnight UTC.
基于研究整理的最佳实践——请留意这些内容,尤其是套餐受限功能和集成相关的注意事项可能会过时。
- 美国区和欧盟区需要使用对应基础URL,域名创建后无法切换区域。 美国区域名使用,欧盟区域名使用
https://api.mailgun.net/v3/。域名在某个区域创建后无法迁移到另一个区域。如果你需要符合GDPR合规要求的欧盟数据驻留,请从一开始就在欧盟区创建域名。使用错误的基础URL会返回鉴权错误,调试难度较高。https://api.eu.mailgun.net/v3/ - Mailgun Optimize是独立付费附加组件($49+/月),不包含在任何发送套餐中。 收件箱投放种子测试、邮箱验证、发件人信誉监控和黑名单告警都需要在发送套餐之外额外订阅Optimize服务。不要假设Foundation或Scale套餐包含这些功能——它们并不包含。
- 域名发送密钥仅可用于发送邮件——无法管理域名、路由或webhook。 如果你的应用需要创建路由、管理域名或配置webhook,必须使用主API密钥。域名发送密钥出于安全隔离考虑,仅允许调用接口。使用域名发送密钥调用其他API会返回401错误。
/messages - 专用IP每个收费$59/月,需要预热——不要假设它们包含在套餐中。 专用IP是Scale和企业版套餐可选的附加组件。新的专用IP初始没有信誉,需要逐步预热(从低发送量开始,在2-4周内逐步提升)。在未预热的专用IP上发送大量邮件会导致极差的送达率。对于低发送量场景,Mailgun的共享IP池通常投递效果更好。
- 免费版额度是每天100封(不是每月)——测试限制非常严格。 对于开发和测试工作流而言,这个限制比听起来要严格得多。如果你需要测试批量发送、webhook处理或模板渲染的任意规模化场景,至少需要购买Foundation套餐($35/月,5万封/月)。每日额度在UTC时间零点重置。
Step 5 — Related skills
步骤5——相关技能
- — Cross-platform email deliverability — SPF/DKIM/DMARC, warmup, inbox placement
/sales-deliverability - — Opt-in email marketing strategy across tools
/sales-email-marketing - — Email engagement tracking strategy
/sales-email-tracking - — Connect Mailgun to CRM, Slack, or other tools via webhooks/Zapier
/sales-integration - — SendGrid platform help — primary Mailgun competitor
/sales-sendgrid - — Postmark platform help — primary Mailgun competitor
/sales-postmark - — Customer.io platform help — uses Mailgun-like APIs for transactional
/sales-customerio - — Not sure which skill to use? The router matches any sales objective to the right skill. Install:
/sales-donpx skills add sales-skills/sales --skills sales-do
- —— 跨平台邮件送达率优化——SPF/DKIM/DMARC、预热、收件箱投放
/sales-deliverability - —— 跨工具的许可式邮件营销策略
/sales-email-marketing - —— 邮件engagement追踪策略
/sales-email-tracking - —— 通过webhook/Zapier将Mailgun连接到CRM、Slack或其他工具
/sales-integration - —— SendGrid平台使用帮助——Mailgun的主要竞争对手
/sales-sendgrid - —— Postmark平台使用帮助——Mailgun的主要竞争对手
/sales-postmark - —— Customer.io平台使用帮助——使用类似Mailgun的API处理事务性邮件
/sales-customerio - —— 不确定使用哪个技能?路由会将任何销售目标匹配到合适的技能。安装命令:
/sales-donpx skills add sales-skills/sales --skills sales-do
Examples
示例
Example 1: Sending transactional email via the REST API in a Node.js app
示例1:在Node.js应用中通过REST API发送事务性邮件
User says: "I need to send password reset and order confirmation emails from my Node.js app using Mailgun."
Skill does:
- Guides creating a Mailgun account and copying the API key from the dashboard
- Walks through adding and verifying a sending domain — adding MX, SPF (), and DKIM DNS records
include:mailgun.org - Shows how to use the SDK: initialize with API key and domain, then call
mailgun.jswithmg.messages.create(),from,to,subject/htmltext - Creates two domain-level templates with Handlebars variables — one for password reset (,
{{reset_url}}) and one for order confirmation ({{expiry_minutes}},{{order_number}},{{items}}){{total}} - Recommends creating a Domain Sending Key for production to limit the key's scope to sending only
- Sets up webhooks for ,
delivered, andpermanent_failevents to monitor delivery health and trigger alerts Result: User has production-ready transactional email with templates, scoped API keys, proper DNS authentication, and delivery monitoringcomplained
用户说: "我需要使用Mailgun从我的Node.js应用发送密码重置和订单确认邮件。"
技能执行动作:
- 指导用户创建Mailgun账户,从后台复制API密钥
- 引导用户添加并验证发送域名——添加MX、SPF()和DKIM DNS记录
include:mailgun.org - 展示如何使用SDK:使用API密钥和域名初始化,调用
mailgun.js并传入mg.messages.create()、from、to、subject/html参数text - 创建两个域名级模板,使用Handlebars变量——一个用于密码重置(、
{{reset_url}}),一个用于订单确认({{expiry_minutes}}、{{order_number}}、{{items}}){{total}} - 建议生产环境创建域名发送密钥,将密钥权限限制为仅可发送邮件
- 为、
delivered和permanent_fail事件设置webhook,监控投递健康度并触发告警 结果: 用户获得生产可用的事务性邮件配置,包含模板、权限受限的API密钥、正确的DNS鉴权和投递监控complained
Example 2: Setting up inbound email routing for a support system
示例2:为支持系统设置入站邮件路由
User says: "We want to receive customer reply emails at support@ourdomain.com and forward them to our ticketing webhook."
Skill does:
- Guides adding an MX record for pointing to Mailgun's inbound servers
ourdomain.com - Verifies the domain in the Mailgun UI
- Creates a route via the API: with action
match_recipient("support@ourdomain.com")forward("https://app.ourdomain.com/api/tickets/inbound") - Explains the webhook payload format — sender, subject, stripped-text (clean body without quoted reply), attachments as file uploads
- Recommends a fallback route with to store unmatched inbound email for 3 days (
catch_all()) so nothing is silently droppedstore(notify="https://app.ourdomain.com/api/catchall") - Shows how to use custom parsing rules with regex to extract ticket IDs from subject lines for routing to existing tickets Result: User has inbound email routing that forwards customer replies to their ticketing system with a catch-all safety net
用户说: "我们希望接收发送到support@ourdomain.com的客户回复邮件,并将它们转发到我们的工单系统webhook。"
技能执行动作:
- 指导用户为添加指向Mailgun入站服务器的MX记录
ourdomain.com - 在Mailgun UI中验证域名
- 通过API创建路由:,动作设置为
match_recipient("support@ourdomain.com")forward("https://app.ourdomain.com/api/tickets/inbound") - 解释webhook payload格式——发件人、主题、stripped-text(去除引用回复的干净正文)、作为文件上传的附件
- 建议使用创建兜底路由,将未匹配的入站邮件存储3天(
catch_all()),避免邮件静默丢失store(notify="https://app.ourdomain.com/api/catchall") - 展示如何使用正则自定义解析规则,从主题行提取工单ID,路由到现有工单 结果: 用户获得可用的入站邮件路由配置,可将客户回复转发到工单系统,并配备兜底安全机制
Example 3: Improving deliverability with Mailgun Optimize
示例3:使用Mailgun Optimize提升送达率
User says: "Our Mailgun emails are landing in spam at Gmail. How do we diagnose and fix this?"
Skill does:
- Checks if the user has Mailgun Optimize — if not, recommends the Pilot plan ($49/mo) for inbox placement testing
- Runs an inbox placement seed test to confirm where emails land across Gmail, Outlook, Yahoo, and other providers
- Reviews domain DNS authentication — verifies SPF, DKIM, and DMARC records are properly configured via the Domains API
- Checks sender reputation in the Optimize dashboard for blocklist appearances and reputation scores
- Validates the sending list via bulk CSV upload to remove invalid, disposable, and risky addresses (reducing bounce rates by up to 21%)
- Reviews the webhook events to identify content or recipients generating spam complaints Result: User identifies the root cause of spam placement (e.g., missing DMARC, blocklisted IP, high bounce rate) and has a concrete remediation plan with ongoing monitoring
complained
用户说: "我们通过Mailgun发送的邮件在Gmail中进入了spam文件夹,如何诊断和修复这个问题?"
技能执行动作:
- 检查用户是否开通了Mailgun Optimize——如果没有,建议订阅Pilot套餐($49/月)用于收件箱投放测试
- 运行收件箱投放种子测试,确认邮件在Gmail、Outlook、Yahoo等各大服务商的投递位置
- 检查域名DNS鉴权配置——通过域名API验证SPF、DKIM和DMARC记录是否正确配置
- 在Optimize后台检查发件人信誉,确认是否被列入黑名单以及信誉分数
- 通过CSV上传批量验证发送列表,移除无效、临时和高风险地址(最多可降低21%退信率)
- 查看webhook事件,识别导致垃圾投诉的内容或收件人 结果: 用户定位到邮件进入spam的根本原因(例如缺少DMARC、IP被列入黑名单、退信率过高),并获得具体的修复方案和持续监控机制
complained
Troubleshooting
故障排查
Emails rejected with 401 Unauthorized when using Domain Sending Key
使用域名发送密钥时邮件被拒绝,返回401 Unauthorized
Symptom: API calls return 401 Unauthorized for endpoints like or , but sending email works fine
Cause: Domain Sending Keys are restricted to endpoints only. They cannot be used to manage domains, routes, webhooks, mailing lists, or any other Mailgun resource. This is by design for security isolation.
Solution: Use your main API key (found in the Mailgun dashboard under API Security) for non-sending operations. Reserve Domain Sending Keys for production sending code only. If you need to manage resources programmatically, store the main API key securely in environment variables and use it for admin operations in a separate service or deployment pipeline.
GET /v3/domainsPOST /v3/routes/messages症状: 调用或等接口时返回401 Unauthorized,但发送邮件正常
原因: 域名发送密钥仅允许调用接口,无法用于管理域名、路由、webhook、邮件列表或任何其他Mailgun资源,这是出于安全隔离的设计。
解决方案: 非发送操作使用主API密钥(可在Mailgun后台的API安全页面找到)。域名发送密钥仅保留给生产环境的发送代码使用。如果你需要程序化管理资源,请将主API密钥安全存储在环境变量中,在单独的服务或部署流水线中用于管理操作。
GET /v3/domainsPOST /v3/routes/messagesWebhook events not arriving at endpoint
Webhook事件没有推送到端点
Symptom: You configured webhooks in Mailgun but your endpoint is not receiving any events — no requests appear in your server logs
Cause: Common causes include: (1) the webhook URL is not publicly accessible (localhost or behind a firewall), (2) the endpoint is returning non-2xx status codes causing Mailgun to back off after retries, (3) the webhook was configured for the wrong domain, or (4) the events are not being generated (e.g., open/click tracking is not enabled).
Solution: Verify your endpoint is publicly accessible — use a tool like ngrok for local development. Check the Mailgun dashboard under Sending > Webhooks for delivery status and recent attempts. Ensure your endpoint returns a 200 status code quickly (within a few seconds). Confirm the webhook is configured for the correct domain. For open/click events, verify tracking is enabled in domain settings. Test with a simple endpoint (e.g., webhook.site) to isolate whether the issue is with Mailgun's delivery or your endpoint's handling.
症状: 你在Mailgun中配置了webhook,但你的端点没有收到任何事件——服务器日志中没有相关请求
原因: 常见原因包括:(1) webhook URL不是公网可访问的(localhost或位于防火墙后),(2) 端点返回非2xx状态码,导致Mailgun重试后停止推送,(3) webhook配置在了错误的域名下,(4) 事件没有生成(例如没有开启打开/点击追踪)。
解决方案: 验证你的端点是公网可访问的——本地开发可使用ngrok等工具。在Mailgun后台的发送>Webhook页面查看投递状态和最近尝试记录。确保你的端点能快速(几秒内)返回200状态码。确认webhook配置在正确的域名下。对于打开/点击事件,请确认域名设置中开启了追踪功能。使用简单的测试端点(例如webhook.site)隔离问题,确认是Mailgun投递问题还是你的端点处理问题。
Emails sending from US region but domain is in EU (or vice versa)
邮件从美国区发送但域名属于欧盟区(反之亦然)
Symptom: API calls return 404 or authentication errors when trying to send email, even though the domain is verified and the API key is correct
Cause: The domain was created in one region (US or EU) but the API calls are being made to the other region's base URL. US domains must use , EU domains must use . Domains cannot be moved between regions after creation.
Solution: Check which region your domain is in via the Mailgun dashboard (look for the region indicator on the domain page). Update your API base URL to match the domain's region. If you need to switch regions (e.g., for GDPR compliance), you must delete the domain and recreate it in the correct region — then re-verify DNS records. Update all application configuration, environment variables, and SDK initialization to use the correct regional URL.
https://api.mailgun.net/v3/https://api.eu.mailgun.net/v3/症状: 即使域名已验证且API密钥正确,调用发送邮件API时仍返回404或鉴权错误
原因: 域名创建在某个区域(美国或欧盟),但API调用使用了另一个区域的基础URL。美国区域名必须使用,欧盟区域名必须使用。域名创建后无法在区域间迁移。
解决方案: 通过Mailgun后台查看域名所属区域(域名页面有区域标识)。更新API基础URL匹配域名的区域。如果你需要切换区域(例如为了GDPR合规),必须删除域名并在正确区域重新创建——然后重新验证DNS记录。更新所有应用配置、环境变量和SDK初始化代码,使用正确的区域URL。
https://api.mailgun.net/v3/https://api.eu.mailgun.net/v3/