Email

From tinh2/skills-hub-registry · View interactive version

Email is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Add transactional email to my app — set up Resend, SendGrid, SES, Postmark, or Mailgun with HTML templates for welcome, password reset, and notification emails, delivery webhooks, bounce handling, and suppression lists

How to use this skill

Skill file

You are in AUTONOMOUS MODE. Do NOT ask questions. Execute the full pipeline below

without pausing for user input. Make reasonable decisions using sensible defaults.

PURPOSE:

Set up a complete transactional email system in the current project. This includes

provider SDK installation, API key configuration, an email service layer, reusable

email templates, delivery tracking via webhooks, and verification that sending works.

INPUT:

$ARGUMENTS

The user may specify:

  1. Provider: "sendgrid", "resend", "ses", "postmark", "mailgun" (default: "resend")
  2. Templates to create: "welcome", "password-reset", "notification", "invoice", or "all"
  3. Additional requirements: "tracking", "webhooks", "batch"

If no arguments, default to Resend with welcome + password-reset + notification templates.

=== PHASE 1: PROJECT DETECTION ===

Step 1.1 — Detect Framework

Scan for project files to determine the tech stack:

| File | Framework | Email Service Location |

|------|-----------|----------------------|

| package.json with "next" | Next.js | lib/email.ts or src/lib/email.ts |

| package.json with "fastify" | Fastify | src/services/email.service.ts |

| package.json with "express" | Express | src/services/email.service.ts |

| package.json with "nestjs" | NestJS | src/email/email.service.ts |

| requirements.txt with "django" | Django | apps/email/services.py |

| requirements.txt with "fastapi" | FastAPI | app/services/email.py |

| Gemfile with "rails" | Rails | app/mailers/ |

Record: FRAMEWORK, LANGUAGE, PROJECT_ROOT, SERVICE_DIR

Step 1.2 — Check Existing Email Setup

Search for any existing email integration:

If a complete email integration exists, report it and exit.

If partial, identify gaps and fill them.

Step 1.3 — Select Provider

If the user specified a provider, use it. Otherwise, auto-select:

Record: PROVIDER

=== PHASE 2: SDK INSTALLATION ===

Step 2.1 — Install Provider SDK

Based on the selected provider:

Resend:

SendGrid:

AWS SES:

Postmark:

Mailgun:

Step 2.2 — Install Template Engine (if needed)

If the project does not already have a template engine for email rendering:

OR npm install handlebars (for simpler template needs)

Step 2.3 — Configure Environment Variables

Add to .env.example:

Resend:

RESEND_API_KEY=re_...
EMAIL_FROM=noreply@yourdomain.com

SendGrid:

SENDGRID_API_KEY=SG....
EMAIL_FROM=noreply@yourdomain.com

AWS SES:

AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
EMAIL_FROM=noreply@yourdomain.com

Postmark:

POSTMARK_API_KEY=
EMAIL_FROM=noreply@yourdomain.com

Update config validation if the project uses one.

=== PHASE 3: EMAIL SERVICE ===

Step 3.1 — Create Email Client Module

Create a provider-specific client at the appropriate location:

The client module MUST:

Step 3.2 — Create Email Service Layer

Create the email service with a provider-agnostic interface:

class EmailService {
  async send(params: {
    to: string | string[];
    subject: string;
    html: string;
    text?: string;
    from?: string;
    replyTo?: string;
    tags?: Record<string, string>;
    attachments?: Array<{ filename: string; content: Buffer }>;
  }): Promise<{ id: string; success: boolean }>

  async sendTemplate(params: {
    to: string | string[];
    template: string;       // template name: "welcome", "password-reset", etc.
    data: Record<string, unknown>;  // template variables
    from?: string;
    replyTo?: string;
  }): Promise<{ id: string; success: boolean }>

  async sendBatch(params: {
    messages: Array<{
      to: string;
      subject: string;
      html: string;
      text?: string;
    }>;
  }): Promise<{ ids: string[]; success: boolean }>
}

The service MUST:

Step 3.3 — Create Provider Adapter

Implement the provider-specific adapter that EmailService delegates to:

Resend adapter:

SendGrid adapter:

SES adapter:

This adapter pattern allows swapping providers without changing calling code.

=== PHASE 4: EMAIL TEMPLATES ===

Step 4.1 — Create Template Directory

Create an email templates directory:

Step 4.2 — Create Welcome Template

Template name: "welcome"

Variables: { userName, appName, loginUrl }

Content structure:

Step 4.3 — Create Password Reset Template

Template name: "password-reset"

Variables: { userName, resetUrl, expiryMinutes }

Content structure:

Step 4.4 — Create Notification Template

Template name: "notification"

Variables: { userName, title, message, actionUrl, actionText }

Content structure:

Step 4.5 — Create Base Layout

Create a shared base layout that all templates extend:

=== PHASE 5: DELIVERY TRACKING ===

Step 5.1 — Create Webhook Endpoint for Delivery Events

Route: POST /api/webhooks/email (or framework equivalent)

Handle provider-specific delivery events:

Resend events:

SendGrid events:

SES events (via SNS):

The webhook handler MUST:

Step 5.2 — Create Delivery Status Types

Define delivery status enum:

enum EmailDeliveryStatus {
  QUEUED      // Accepted by provider, not yet sent
  SENT        // Sent to recipient's mail server
  DELIVERED   // Confirmed delivery to inbox
  OPENED      // Recipient opened the email (if tracking enabled)
  CLICKED     // Recipient clicked a link (if tracking enabled)
  BOUNCED     // Hard bounce — address invalid
  DEFERRED    // Soft bounce — temporary failure, will retry
  DROPPED     // Provider rejected (suppression list, invalid)
  COMPLAINED  // Recipient marked as spam
}

Step 5.3 — Create Suppression List Handler

Create a module that manages email suppression:

=== PHASE 6: VERIFICATION ===

Step 6.1 — Static Verification

Run the project's type checker and linter:

Step 6.2 — Integration Checklist

Verify and report:

=== OUTPUT ===

Print the following summary:


Email Integration Complete

Framework: [detected framework]

Provider: [selected provider]

Templates created: [list]

Files Created/Modified

| File | Purpose |

|------|---------|

| [path] | [description] |

Environment Variables Required

| Variable | Purpose | Where to get it |

|----------|---------|-----------------|

| [KEY] | [purpose] | [provider dashboard URL] |

| EMAIL_FROM | Default sender address | Must match verified domain |

Email Templates

| Template | Variables | Usage |

|----------|-----------|-------|

| welcome | userName, appName, loginUrl | After user registration |

| password-reset | userName, resetUrl, expiryMinutes | Password reset request |

| notification | userName, title, message, actionUrl | General notifications |

Usage Example

import { emailService } from './services/email.service';

await emailService.sendTemplate({
  to: user.email,
  template: 'welcome',
  data: { userName: user.name, appName: 'MyApp', loginUrl: 'https://myapp.com/login' },
});

Domain Verification

To send from your own domain:

  1. Add DNS records (SPF, DKIM, DMARC) as specified by [provider]
  2. Verify domain in [provider] dashboard
  3. Update EMAIL_FROM to use your verified domain

Webhook Configuration


=== NEXT STEPS ===

After email integration:

=== DO NOT ===

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the integration, validate:

  1. Run the project's test suite to verify the integration works end-to-end.
  2. Run build/compile to confirm no breakage.
  3. Verify the integration responds correctly (health checks, test calls, smoke tests).
  4. If failures occur, diagnose from error output and apply minimal fixes.
  5. Repeat up to 3 iterations.

IF STILL FAILING after 3 iterations:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /email — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.