Communitygithub.com

mailtrap-email-integration

エージェントがMailtrapを介したトランザクションメール送信を統合するためのガイド

mailtrap-email-integration とは?

このスキルは、MailtrapのEmail APIとSandboxを使用してアプリケーションにトランザクションメール送信を追加するための包括的なガイドを提供します。認証、環境分離、および一般的な配信の問題をカバーしており、開発者やAIエージェントが「メール送信」機能(サインアップ確認、パスワードリセット、通知など)を実装する際に役立ちます。Sandboxは開発・ステージング環境でメールをキャプチャし実際の受信トレイに配信しないため、テストメールが実在のユーザーに届くリスクを防ぎます。一方、本番環境では検証済みドメインを使用した専用エンドポイントで送信を行います。コード例(TypeScript)、アンチパターン、ベストプラクティスも含まれており、Claude Code、Coder、Cline、Copilot、Cursorなどの主要なAIエージェントツールで利用可能です。

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

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Mailtrap Email Integration

MailtrapのEmail APIとSandboxを使用してアプリケーションにトランザクションメール送信を追加するためのパターン。認証、環境分離、および一般的な配信の落とし穴をカバーします。

アクティベーション条件

  • 「メール送信」機能(サインアップ確認、パスワードリセット、通知、領収書)を実装する場合
  • 開発/ステージング環境でメールが届かない理由をデバッグする場合
  • プロジェクトで初めてメール送信インテグレーションを設定する場合
  • Sandbox分離なしでメールAPIを直接呼び出すコードをレビューする場合

コアコンセプト

Sandboxと本番環境の分離。 MailtrapはSandbox APIを提供し、メールをキャプチャして配信しません。開発/ステージング環境で使用すると、テストメールが実際の受信トレイに届くことがありません。本番送信には、別途検証済みドメインのエンドポイントを使用します。開発環境を本番送信エンドポイントに決して向けてはいけません。

認証。 リクエストにはAuthorizationヘッダーにBearerトークンを使用します。トークンはプロジェクトごとにスコープ設定されており、Sandboxと本番環境では通常異なるトークンを使用します。

ドメイン検証。 本番送信には、DNSレコード(SPF、DKIM、DMARC)を介して送信ドメインを検証する必要があります。これを省略すると、メールが静かに配信に失敗したり、スパムフォルダに入ったりします。

コード例

// 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();
}
// 同じ呼び出しを非本番環境でSandboxにルーティング
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}`;

アンチパターン

アンチパターン問題点代わりに
開発/テスト環境で本番送信エンドポイントを使用する実際のテストメールが実際の受信トレイに届き、スパム苦情やテストデータ漏洩のリスクが発生する非本番環境をSandboxエンドポイントにルーティングする
ソースコードにAPIトークンをハードコーディングするバージョン管理にコミットした場合、認証情報漏洩のリスクがある環境変数/シークレットマネージャーからトークンを読み込む
ドメイン検証が完了する前に送信するメールが静かに失敗したり、スパムに分類される本番送信を有効にする前にSPF/DKIM/DMARCレコードを検証する
送信失敗時のリトライ/エラーハンドリングがない通知が静かに失敗する(例:ユーザーがパスワードリセットメールを受け取れない)レスポンスステータスを確認し、失敗をログに記録し、実行可能なエラーを表面化する

ベストプラクティス

  • Sandboxと本番環境のトークンは別々の環境変数に保持し、環境間でトークンを共有しない
  • メールを伴う本番リリースの前に、送信ドメインの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.

関連スキル