Communitygithub.com

mailtrap-email-integration

引導 AI 代理整合 Mailtrap 的 Email API 與 Sandbox,處理交易郵件發送、驗證及環境分離。

mailtrap-email-integration 是什麼?

此技能旨在協助開發者或 AI 代理快速將 Mailtrap 的交易郵件發送功能整合進應用程式。它詳細說明了如何區分 Sandbox(沙箱)與正式環境,避免測試郵件誤傳至真實收件匣。技能涵蓋了使用 Bearer Token 進行身分驗證、DNS 網域驗證(SPF、DKIM、DMARC)等核心概念,並提供了 TypeScript 的實際程式碼範例,展示如何透過 Email API 發送郵件以及根據環境動態切換端點。此外,技能還列出了常見的反模式(如硬編碼 Token、在開發環境使用正式端點)以及最佳實務(如分離環境變數、錯誤處理與重試機制)。支援平台包括 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 提供一個沙箱 API,可攔截郵件而不實際投遞,用於開發/測試環境,確保測試郵件不會進入真實收件匣。正式環境則使用另一個經過網域驗證的端點。絕不要將開發環境指向正式發送端點。

身分驗證。 請求需要在 Authorization 標頭中使用 Bearer Token。Token 是依專案範圍區分的;沙箱與正式環境通常使用不同的 Token。

網域驗證。 正式發送需要先透過 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: "您的應用程式" },
      to: [{ email: to }],
      subject,
      html,
    }),
  });

  if (!response.ok) {
    throw new Error(`郵件發送失敗:${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 Token若提交至版本控制,可能造成憑證外洩從環境變數/密碼管理工具載入 Token
在網域驗證完成前就開始發送郵件會無聲失敗或落入垃圾郵件在啟用正式發送前,先驗證 SPF/DKIM/DMARC 記錄
發送失敗時未做重試/錯誤處理通知無聲失敗(例如使用者永遠收不到密碼重設郵件)檢查回應狀態、記錄失敗原因、提供可操作的錯誤訊息

最佳實務

  • 將沙箱與正式環境的 Token 存放在不同的環境變數中,切勿共用一個 Token 給不同環境
  • 在涉及郵件的正式版本上線前,先驗證寄件網域的 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.

相關技能