Communitygithub.com

mailtrap-email-integration

指导代理通过Mailtrap集成事务性电子邮件发送。

mailtrap-email-integration 是什么?

该技能旨在帮助开发者通过Mailtrap的Email API和Sandbox将其应用程序中的事务性电子邮件发送功能集成起来。它涵盖了身份验证、开发/生产环境分离以及常见投递陷阱等核心概念。技能提供了清晰的代码示例,展示了如何在不同环境中安全地切换沙箱和生产端点,并详细说明了域名验证(SPF、DKIM、DMARC)的必要性。通过识别反模式(如硬编码令牌、在开发环境中使用生产端点)并推荐最佳实践(如将令牌存储在环境变量中、添加错误重试机制),该技能确保电子邮件发送在生产环境中可靠,在开发测试环境中安全隔离。它主要支持平台如Claude Code、Cursor或Codex等AI代理工具,帮助用户在实现“发送邮件”功能时快速获得正确引导。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/ECC/tree/main/skills/mailtrap-email-integration

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Mailtrap 电子邮件集成

使用Mailtrap的Email API和Sandbox为应用程序添加事务性电子邮件发送功能的模式,涵盖身份验证、环境分离和常见投递陷阱。

何时激活

  • 实现“发送邮件”功能(注册确认、密码重置、通知、收据)
  • 调试为什么开发/预发环境中邮件未到达
  • 设置项目的第一个电子邮件发送集成
  • 审查直接调用电子邮件API而没有沙箱分离的代码

核心概念

沙箱与生产环境的分离。 Mailtrap提供了Sandbox API,它捕获电子邮件而不实际投递,用于开发/预发环境,以便测试邮件永远不会到达真实的收件箱。生产发送使用独立的已验证域名端点。切勿将开发环境指向生产发送端点。

身份验证。 请求使用Authorization头中的Bearer令牌。令牌按项目作用域划分;沙箱和生产环境通常使用不同的令牌。

域名验证。 生产发送需要通过DNS记录(SPF、DKIM、DMARC)验证发送域名,然后Mailtrap才会将邮件投递给真实收件人。跳过此步骤会导致静默投递失败或进入垃圾邮件文件夹。

代码示例

// 通过Mailtrap的Email API发送(生产环境)
async function sendEmail(to: string, subject: string, html: string) {
  const response = await fetch("https://send.api.mailtrap.io/api/send", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${process.env.MAILTRAP_API_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      from: { email: "[email protected]", name: "Your App" },
      to: [{ email: to }],
      subject,
      html,
    }),
  });

  if (!response.ok) {
    throw new Error(`Email send failed: ${response.status}`);
  }
  return response.json();
}
// 相同调用,在非生产环境中路由到沙箱
const MAILTRAP_ENDPOINT = process.env.NODE_ENV === "production"
  ? "https://send.api.mailtrap.io/api/send"
  : `https://sandbox.api.mailtrap.io/api/send/${process.env.MAILTRAP_INBOX_ID}`;

反模式

反模式为什么有问题替代方案
在开发/测试中使用生产发送端点真实的测试邮件会到达真实收件箱,带来垃圾邮件投诉和测试数据泄露的风险将非生产环境路由到沙箱端点
在源代码中硬编码API令牌如果提交到版本控制,存在凭证泄露风险从环境变量/密钥管理器加载令牌
在域名验证完成之前发送邮件邮件静默失败或进入垃圾邮件在启用生产发送前验证SPF/DKIM/DMARC记录
发送失败时没有重试/错误处理静默的通知失败(例如用户从未收到密码重置邮件)检查响应状态、记录失败、提供可操作错误信息

最佳实践

  • 将沙箱和生产环境的令牌放在不同的环境变量中,切勿跨环境共享一个令牌
  • 在任何涉及电子邮件发送的生产启动之前验证发送域名的DNS记录
  • 记录投递失败,并提供足够的上下文以便调试(收件人、模板、时间戳、响应代码)
  • 将电子邮件发送视为可能失败的网络调用:用try/catch包裹,切勿假设成功

相关技能

api-and-interface-design、security-and-hardening、ci-cd-and-automation

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/content-engine

Create platform-native content systems for X, LinkedIn, TikTok, YouTube, newsletters, and repurposed multi-platform campaigns. Use when the user wants social posts, threads, scripts, content calendars, or one source asset adapted cleanly across platforms.

affaan-m/ECC

Multi-platform content distribution across X, LinkedIn, Threads, and Bluesky. Adapts content per platform using content-engine patterns. Never posts identical content cross-platform. Use when the user wants to distribute content across social platforms.

affaan-m/fal-ai-media

Unified media generation via fal.ai MCP — image, video, and audio. Covers text-to-image (Nano Banana), text/image-to-video (Seedance, Kling, Veo 3), text-to-speech (CSM-1B), and video-to-audio (ThinkSound). Use when the user wants to generate images, videos, or audio with AI.

affaan-m/manim-video

日本語翻訳:このファイルは manim-video 用の日本語翻訳が必要です

affaan-m/remotion-video-creation

Remotion のベストプラクティス - React で動画を作成する。3D、アニメーション、音声、字幕、チャート、トランジションなどをカバーするドメイン固有の29のルール。

affaan-m/video-editing

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

agent-self-evaluation

Use after completing any non-trivial task. The agent self-rates its output on 5 axes — accuracy, completeness, clarity, actionability, conciseness — with concrete evidence per criterion. Produces a structured 1-5 scorecard with specific improvement suggestions.

agent-sort

Build an evidence-backed ECC install plan for a specific repo by sorting skills, commands, rules, hooks, and extras into DAILY vs LIBRARY buckets using parallel repo-aware review passes. Use when ECC should be trimmed to what a project actually needs instead of loading the full bundle.

ai-first-engineering

Engineering operating model for teams where AI agents generate a large share of implementation output. Use when setting team process, review gates, or ownership rules for a codebase largely written by agents.

ai-regression-testing

Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots where the same model writes and reviews code. Use when adding regression coverage to AI-assisted code, or when the same model both wrote and reviewed a change.

android-clean-architecture

Clean Architecture patterns for Android and Kotlin Multiplatform projects — module structure, dependency rules, UseCases, Repositories, and data layer patterns. Use when structuring modules, layers, or data flow in an Android or KMP project.

angular-developer

Generates Angular code and provides architectural guidance. Trigger when creating projects, components, or services, or for best practices on reactivity (signals, linkedSignal, resource), forms, dependency injection, routing, SSR, accessibility (ARIA), animations, styling (component styles, Tailwind CSS), testing, or CLI tooling.

相关技能