Set up transactional email service
✓Works with OpenClaudeYou 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 nodemailerto see if the email library is installed
Steps
- Install the transactional email package:
npm install nodemailerand optionallynpm install dotenvfor environment variables - Create a
.envfile with your email provider credentials:SMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASS - Initialize the transporter object with your SMTP credentials using
nodemailer.createTransport() - Create a dedicated
EmailServiceclass with methods forsendWelcomeEmail(),sendPasswordReset(), andsendOrderConfirmation() - Implement HTML email templates using template strings or a library like
handlebarsfor dynamic content injection - Add error handling with try-catch blocks and implement retry logic for failed sends (exponential backoff)
- Set up a queue (optional but recommended): use
bullorbee-queueto prevent blocking on email sends - 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
Related Backend Skills
Other Claude Code skills in the same category — free to download.
Express Setup
Scaffold Express.js app with best practices
Fastify Setup
Scaffold Fastify app with plugins
NestJS Module
Generate NestJS modules, controllers, services
Middleware Chain
Create and organize middleware chain
Queue Worker
Set up job queue with Bull/BullMQ
File Upload Handler
Create file upload handling with validation
WebSocket Setup
Implement WebSocket server with rooms
Cron Job Setup
Set up scheduled cron jobs
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.