Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Backendintermediate

Email Service

Share

Set up transactional email service

Works with OpenClaude

You are a backend engineer setting up a production-ready transactional email service. The user wants to configure and implement reliable email delivery with templates, error handling, and verification.

What to check first

  • Verify Node.js version: node --version (requires 14.0+)
  • Check if a mail service provider account exists (SendGrid, AWS SES, or Mailgun)
  • Run npm list nodemailer to see if the email library is installed

Steps

  1. Install the transactional email package: npm install nodemailer and optionally npm install dotenv for environment variables
  2. Create a .env file with your email provider credentials: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS
  3. Initialize the transporter object with your SMTP credentials using nodemailer.createTransport()
  4. Create a dedicated EmailService class with methods for sendWelcomeEmail(), sendPasswordReset(), and sendOrderConfirmation()
  5. Implement HTML email templates using template strings or a library like handlebars for dynamic content injection
  6. Add error handling with try-catch blocks and implement retry logic for failed sends (exponential backoff)
  7. Set up a queue (optional but recommended): use bull or bee-queue to prevent blocking on email sends
  8. Test with a sandbox account first before sending to production addresses

Code

const nodemailer = require('nodemailer');
const path = require('path');
require('dotenv').config();

class EmailService {
  constructor() {
    this.transporter = nodemailer.createTransport({
      host: process.env.SMTP_HOST,
      port: process.env.SMTP_PORT,
      secure: process.env.SMTP_PORT === '465',
      auth: {
        user: process.env.SMTP_USER,
        pass: process.env.SMTP_PASS,
      },
    });
  }

  async sendWelcomeEmail(recipientEmail, userName) {
    const htmlTemplate = `
      <h1>Welcome, ${userName}!</h1>
      <p>Thank you for signing up. Your account is now active.</p>
      <a href="${process.env.APP_URL}/verify?email=${recipientEmail}">Verify Email</a>
    `;

    try {
      const result = await this.transporter.sendMail({
        from: process.env.SENDER_EMAIL,
        to: recipientEmail,
        subject: 'Welcome to Our Platform',
        html: htmlTemplate,
      });
      console.log('Welcome email sent:', result.messageId);
      return result;
    } catch (error) {
      console.error('Failed to send welcome email:', error);
      throw error;
    }
  }

  async sendPasswordReset(recipientEmail, resetToken) {
    const resetLink =

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryBackend
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
backendemailservice

Install command:

curl -o ~/.claude/skills/email-service.md https://claude-skills-hub.vercel.app/skills/backend/email-service.md

Related Backend Skills

Other Claude Code skills in the same category — free to download.

Want a Backend skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.