Email Expert

The Email Expert agent specializes in email integration, transactional emails, email templates, and email service providers for applications.

Expertise Areas#

  • Resend Integration - Modern email API setup
  • React Email Templates - Component-based email design
  • Email Service Layer - Centralized email management
  • Magic Link Authentication - Passwordless email login
  • Email Queues - Background job processing
  • Email Preferences - User subscription management
  • Deliverability - Best practices for inbox placement

Usage Examples#

Resend Setup#

Use the email-expert agent to set up Resend for transactional emails in a Next.js application.

Response includes:

  • SDK configuration
  • Send function implementation
  • Error handling
  • Domain setup guidance

React Email Templates#

Use the email-expert agent to create a welcome email template using React Email.

Response includes:

  • Component structure
  • Styling approach
  • Dynamic content
  • Preview setup
Use the email-expert agent to implement passwordless authentication with magic links.

Response includes:

  • Token generation
  • Email sending
  • Verification endpoint
  • Security considerations

Best Practices Applied#

1. Email Design#

  • Responsive templates
  • Consistent branding
  • Clear CTAs
  • Fallback styling

2. Deliverability#

  • Domain verification
  • SPF/DKIM/DMARC
  • List hygiene
  • Engagement tracking

3. User Experience#

  • Clear unsubscribe
  • Preference management
  • Confirmation emails
  • Transactional clarity

4. Operations#

  • Queue processing
  • Retry logic
  • Error tracking
  • Analytics

Common Patterns#

Resend Setup#

1// lib/email.ts 2import { Resend } from 'resend'; 3 4export const resend = new Resend(process.env.RESEND_API_KEY); 5 6export async function sendEmail({ 7 to, 8 subject, 9 html, 10}: { 11 to: string; 12 subject: string; 13 html: string; 14}) { 15 const { data, error } = await resend.emails.send({ 16 from: 'Your App <noreply@yourapp.com>', 17 to, 18 subject, 19 html, 20 }); 21 22 if (error) { 23 console.error('Email error:', error); 24 throw error; 25 } 26 27 return data; 28}

React Email Template#

1// emails/welcome.tsx 2import { 3 Body, 4 Button, 5 Container, 6 Head, 7 Heading, 8 Html, 9 Preview, 10 Text, 11} from '@react-email/components'; 12 13interface WelcomeEmailProps { 14 name: string; 15 actionUrl: string; 16} 17 18export function WelcomeEmail({ name, actionUrl }: WelcomeEmailProps) { 19 return ( 20 <Html> 21 <Head /> 22 <Preview>Welcome to Our App</Preview> 23 <Body style={main}> 24 <Container style={container}> 25 <Heading style={h1}>Welcome, {name}!</Heading> 26 <Text style={text}> 27 Thanks for signing up. We're excited to have you on board. 28 </Text> 29 <Button style={button} href={actionUrl}> 30 Get Started 31 </Button> 32 </Container> 33 </Body> 34 </Html> 35 ); 36} 37 38const main = { 39 backgroundColor: '#f6f9fc', 40 fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif', 41}; 42 43const container = { 44 backgroundColor: '#ffffff', 45 margin: '0 auto', 46 padding: '40px 20px', 47 maxWidth: '560px', 48};

Email Service Layer#

1// lib/email-service.ts 2import { resend } from './email'; 3import { render } from '@react-email/render'; 4import { WelcomeEmail } from '@/emails/welcome'; 5import { PasswordResetEmail } from '@/emails/password-reset'; 6 7export const emailService = { 8 async sendWelcome(to: string, name: string) { 9 const html = await render( 10 WelcomeEmail({ 11 name, 12 actionUrl: `${process.env.NEXT_PUBLIC_APP_URL}/dashboard`, 13 }) 14 ); 15 16 return resend.emails.send({ 17 from: 'Your App <welcome@yourapp.com>', 18 to, 19 subject: 'Welcome to Our App!', 20 html, 21 }); 22 }, 23 24 async sendPasswordReset(to: string, resetUrl: string) { 25 const html = await render(PasswordResetEmail({ resetUrl })); 26 27 return resend.emails.send({ 28 from: 'Your App <security@yourapp.com>', 29 to, 30 subject: 'Reset Your Password', 31 html, 32 }); 33 }, 34};
1// lib/auth/magic-link.ts 2import { emailService } from '@/lib/email-service'; 3import { prisma } from '@/lib/db'; 4import { randomBytes } from 'crypto'; 5 6export async function sendMagicLink(email: string) { 7 const token = randomBytes(32).toString('hex'); 8 const expires = new Date(Date.now() + 15 * 60 * 1000); // 15 minutes 9 10 await prisma.verificationToken.create({ 11 data: { identifier: email, token, expires }, 12 }); 13 14 const magicLink = `${process.env.NEXT_PUBLIC_APP_URL}/auth/verify?token=${token}`; 15 await emailService.sendMagicLink(email, magicLink); 16} 17 18export async function verifyMagicLink(token: string) { 19 const verificationToken = await prisma.verificationToken.findUnique({ 20 where: { token }, 21 }); 22 23 if (!verificationToken || verificationToken.expires < new Date()) { 24 throw new Error('Invalid or expired token'); 25 } 26 27 await prisma.verificationToken.delete({ where: { token } }); 28 return verificationToken.identifier; 29}

Sample Prompts#

TaskPrompt
Setup"Set up Resend for transactional email sending"
Templates"Create a password reset email template with React Email"
Magic link"Implement passwordless authentication with magic links"
Preferences"Add email preference management for users"
Queue"Set up background email processing with Inngest"

Configuration#

1// bootspring.config.js 2module.exports = { 3 agents: { 4 customInstructions: { 5 'email-expert': ` 6 - Use Resend for email delivery 7 - Create templates with React Email 8 - Implement proper error handling 9 - Add unsubscribe functionality 10 - Track email analytics 11 `, 12 }, 13 }, 14 email: { 15 provider: 'resend', 16 domain: 'yourapp.com', 17 }, 18};