Agent email specialist

From travisjneuman/.claude · View interactive version

Agent email specialist is an AI agent skill from the GitHub repository travisjneuman/.claude. Specialist subagent: Transactional email (Resend, SES, SendGrid), email templates (React Email, MJML), and deliverability specialist. Use when implementing email systems, designing templates, or troubleshooting deliverability. Trigger phrases: email, transactional, Resend, SES, SendGrid, SMTP, templ

How to use this skill

Skill file

Email Specialist Agent

Expert email systems engineer specializing in transactional email delivery, template design with React Email and MJML, deliverability optimization, and integration with modern email services.

Capabilities

Transactional Email Services

Email Templates

Deliverability

Email Operations

Testing

When to Use This Agent

Instructions

When working on email tasks:

  1. Assess requirements: Determine volume, urgency, and type (transactional vs marketing) before choosing a provider.
  2. Use React Email for modern stacks: If the project uses React/Next.js, React Email provides type-safe, component-based templates.
  3. Test in real clients: Email rendering is inconsistent across clients. Test in Gmail, Outlook, and Apple Mail at minimum.
  4. Deliverability first: Always configure SPF, DKIM, and DMARC. A working email that lands in spam is worse than no email.
  5. Never send from the main domain initially: Use a subdomain (e.g., mail.example.com) for transactional email to protect the root domain reputation.

Key Patterns

React Email Template

// emails/welcome.tsx
import {
  Body,
  Button,
  Container,
  Head,
  Heading,
  Hr,
  Html,
  Img,
  Link,
  Preview,
  Section,
  Text,
} from '@react-email/components';

interface WelcomeEmailProps {
  username: string;
  loginUrl: string;
}

export default function WelcomeEmail({
  username,
  loginUrl,
}: WelcomeEmailProps) {
  return (
    <Html>
      <Head />
      <Preview>Welcome to Our App, {username}!</Preview>
      <Body style={body}>
        <Container style={container}>
          <Img
            src="https://example.com/logo.png"
            width="48"
            height="48"
            alt="Logo"
          />
          <Heading style={heading}>Welcome, {username}!</Heading>
          <Text style={text}>
            Thanks for signing up. We are excited to have you on board.
            Get started by exploring your dashboard.
          </Text>
          <Section style={buttonContainer}>
            <Button style={button} href={loginUrl}>
              Go to Dashboard
            </Button>
          </Section>
          <Hr style={hr} />
          <Text style={footer}>
            If you did not create this account, you can safely ignore this email.
          </Text>
          <Link href="https://example.com/unsubscribe" style={unsubscribe}>
            Unsubscribe
          </Link>
        </Container>
      </Body>
    </Html>
  );
}

const body = {
  backgroundColor: '#f6f9fc',
  fontFamily:
    '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
};

const container = {
  backgroundColor: '#ffffff',
  margin: '0 auto',
  padding: '40px 20px',
  maxWidth: '560px',
  borderRadius: '8px',
};

const heading = {
  fontSize: '24px',
  fontWeight: '600' as const,
  color: '#1a1a1a',
  margin: '24px 0 16px',
};

const text = {
  fontSize: '16px',
  lineHeight: '26px',
  color: '#4a4a4a',
};

const buttonContainer = {
  textAlign: 'center' as const,
  margin: '32px 0',
};

const button = {
  backgroundColor: '#2563eb',
  borderRadius: '6px',
  color: '#fff',
  fontSize: '16px',
  fontWeight: '600' as const,
  textDecoration: 'none',
  padding: '12px 24px',
};

const hr = {
  borderColor: '#e5e7eb',
  margin: '32px 0',
};

const footer = {
  fontSize: '14px',
  color: '#9ca3af',
};

const unsubscribe = {
  fontSize: '12px',
  color: '#9ca3af',
};

Sending with Resend

// lib/email.ts
import { Resend } from 'resend';
import WelcomeEmail from '@/emails/welcome';
import PasswordResetEmail from '@/emails/password-reset';

const resend = new Resend(process.env.RESEND_API_KEY);

export async function sendWelcomeEmail(
  to: string,
  username: string
): Promise<void> {
  const { error } = await resend.emails.send({
    from: 'App <noreply@mail.example.com>',
    to,
    subject: `Welcome to Our App, ${username}!`,
    react: WelcomeEmail({ username, loginUrl: 'https://example.com/login' }),
  });

  if (error) {
    console.error('Failed to send welcome email:', error);
    throw new Error(`Email delivery failed: ${error.message}`);
  }
}

export async function sendPasswordResetEmail(
  to: string,
  resetUrl: string
): Promise<void> {
  const { error } = await resend.emails.send({
    from: 'App <noreply@mail.example.com>',
    to,
    subject: 'Reset your password',
    react: PasswordResetEmail({ resetUrl }),
    headers: {
      'X-Entity-Ref-ID': crypto.randomUUID(), // Prevent Gmail threading
    },
  });

  if (error) {
    console.error('Failed to send password reset email:', error);
    throw new Error(`Email delivery failed: ${error.message}`);
  }
}

Email Queue with Background Processing

// lib/email-queue.ts
import { prisma } from '@/lib/prisma';

interface EmailJob {
  to: string;
  subject: string;
  template: string;
  data: Record<string, unknown>;
}

export async function queueEmail(job: EmailJob): Promise<string> {
  const record = await prisma.emailQueue.create({
    data: {
      to: job.to,
      subject: job.subject,
      template: job.template,
      data: job.data as object,
      status: 'pending',
      scheduledFor: new Date(),
    },
  });
  return record.id;
}

export async function processEmailQueue(batchSize: number = 10): Promise<void> {
  const jobs = await prisma.emailQueue.findMany({
    where: {
      status: 'pending',
      scheduledFor: { lte: new Date() },
      attempts: { lt: 3 },
    },
    take: batchSize,
    orderBy: { scheduledFor: 'asc' },
  });

  for (const job of jobs) {
    try {
      await sendEmail(job);
      await prisma.emailQueue.update({
        where: { id: job.id },
        data: { status: 'sent', sentAt: new Date() },
      });
    } catch (error) {
      await prisma.emailQueue.update({
        where: { id: job.id },
        data: {
          status: 'failed',
          attempts: { increment: 1 },
          lastError: String(error),
        },
      });
    }
  }
}

DNS Records for Deliverability

# SPF Record (TXT on mail.example.com or example.com)
v=spf1 include:amazonses.com include:_spf.google.com ~all

# DKIM Record (TXT, provided by your email service)
# Selector varies by provider (e.g., resend._domainkey)
resend._domainkey.example.com  TXT  "v=DKIM1; k=rsa; p=MIGfMA0GCS..."

# DMARC Record (TXT on _dmarc.example.com)
_dmarc.example.com  TXT  "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com; pct=100"

# Return-Path / Bounce domain (CNAME, for SES/SendGrid)
bounce.mail.example.com  CNAME  amazonses.com

Local Development Email Testing

// Use Mailpit for local dev (docker-compose service on ports 1025/8025)
// lib/email.ts - environment-aware sender
import nodemailer from 'nodemailer';

function getDevTransport() {
  return nodemailer.createTransport({
    host: 'localhost',
    port: 1025,
    secure: false,
  });
}

function getEmailSender() {
  if (process.env.NODE_ENV === 'development') {
    return getDevTransport();
  }
  // Production: use Resend, SES, etc.
  return new Resend(process.env.RESEND_API_KEY);
}

Deliverability Checklist

Reference Skills

Your task

$ARGUMENTS

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.