# Email Template Service **Production-ready email template service with beautiful React templates and secure backend API.** [![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![React](https://img.shields.io/badge/React-20232A?style=flat&logo=react&logoColor=61DAFB)](https://reactjs.org/) [![Express](https://img.shields.io/badge/Express.js-404D59?style=flat&logo=express)](https://expressjs.com/) [![Docker](https://img.shields.io/badge/Docker-2496ED?style=flat&logo=docker&logoColor=white)](https://www.docker.com/) ## ✨ Features ### πŸ“§ Email Templates - **Event Invitations** - Event invitations with RSVP functionality - **Team Invitations** - Team member invitations with branded styling and acceptance links - **Payment Requests** - Basic payment requests with payment buttons or bank transfer details - **Enhanced Payment Requests** - Detailed payment requests with itemized line items and automatic status updates - **Invoice Sharing** - Secure invoice sharing with expiration and access limits - **Password Reset** - Secure password recovery emails - **Invoices** - Professional proforma invoices - **Tax Reports** - VAT and withholding tax reports - **Newsletters** - Marketing and announcement emails ### πŸ›‘οΈ Production Ready - **Security**: Input validation, rate limiting, CORS protection - **Monitoring**: Health checks, structured logging, error tracking - **Performance**: Optimized templates, request caching - **Reliability**: Comprehensive error handling, graceful shutdown ### 🎨 Developer Experience - **Visual Designer**: React-based template editor - **Type Safety**: Full TypeScript coverage - **Hot Reload**: Development server with instant updates - **Docker Support**: One-command deployment ## πŸš€ Quick Start ### 1. Installation ```bash git clone cd email-template-service npm install ``` ### 2. Environment Setup ```bash cp .env.example .env # Edit .env with your Resend API key and domain ``` ### 3. Development ```bash # Start template designer (frontend) npm run dev # Start API server (backend) - separate terminal npm run server:dev ``` ### 4. Production ```bash # Docker (recommended) docker-compose up -d # Or Node.js npm run build && npm start ``` ## πŸ“‘ API Usage (For Yaltopia Backend) ### Send Invitation Email ```javascript // From your Yaltopia backend when user registers for event const invitationData = { to: user.email, eventName: event.name, dateTime: "March 25, 2026 at 2:00 PM", location: event.location, ctaUrl: `https://yaltopia.com/events/${event.id}/rsvp`, company: { name: "Yaltopia Ticket", logoUrl: "https://yaltopia.com/logo.png" } } const response = await fetch('http://email-service:3001/api/emails/invitation', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(invitationData) }) ``` ### Send Team Invitation ```javascript // From your Yaltopia backend when inviting team members const teamInvitationData = { to: user.email, recipientName: user.name, inviterName: inviter.name, teamName: team.name, invitationLink: `https://yaltopia.com/teams/join?token=${invitationToken}`, customMessage: "Join our team and let's build something amazing!", company: { name: "Yaltopia Ticket", logoUrl: "https://yaltopia.com/logo.png", primaryColor: "#10b981" } } const response = await fetch('http://email-service:3001/api/emails/team-invitation', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(teamInvitationData) }) ``` ### Send Enhanced Payment Request ```javascript // From your Yaltopia backend for detailed payment requests const enhancedPaymentData = { to: customer.email, recipientName: customer.name, paymentRequestNumber: "PR-2026-001", amount: 2500.00, currency: "USD", description: "Monthly subscription and services", dueDate: "March 31, 2026", lineItems: [ { description: "Yaltopia Pro Subscription", quantity: 1, unitPrice: 199.00, total: 199.00 }, { description: "Setup and Configuration", quantity: 5, unitPrice: 150.00, total: 750.00 } ], notes: "Payment is due within 30 days.", company: { name: "Yaltopia Ticket", bankDetails: { bankName: "Your Bank", accountName: "Yaltopia Ticket Ltd", accountNumber: "123456789", referenceNote: "Payment for PR-2026-001" } } } const response = await fetch('http://email-service:3001/api/emails/enhanced-payment-request', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(enhancedPaymentData) }) ``` ### Send Invoice Share ```javascript // From your Yaltopia backend for invoice sharing const invoiceShareData = { to: recipient.email, recipientName: recipient.name, senderName: sender.name, invoiceNumber: invoice.number, customerName: invoice.customer.name, amount: invoice.totalAmount, currency: "USD", status: "SENT", // 'DRAFT', 'SENT', 'PAID', 'OVERDUE', 'CANCELLED' shareLink: `https://yaltopia.com/invoices/shared/${shareToken}`, expirationDate: "March 31, 2026", accessLimit: 5, customMessage: "Please review this invoice.", company: { name: "Yaltopia Ticket", logoUrl: "https://yaltopia.com/logo.png" } } const response = await fetch('http://email-service:3001/api/emails/invoice-share', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(invoiceShareData) }) ``` ### Send Password Reset ```javascript // From your Yaltopia backend for password reset const resetData = { to: user.email, resetLink: `https://yaltopia.com/reset-password?token=${resetToken}`, recipientName: user.firstName, company: { name: "Yaltopia Ticket" } } const response = await fetch('http://email-service:3001/api/emails/password-reset', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(resetData) }) ``` ## πŸ—οΈ Architecture ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Yaltopia β”‚ β”‚ Email Service β”‚ β”‚ Resend β”‚ β”‚ Backend │───▢│ (Express.js) │───▢│ Email API β”‚ β”‚ (with data) β”‚ β”‚ + Templates β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β–Ό β–Ό β–Ό Has Event Data Renders Templates Email Delivery ``` **Simple & Efficient**: Yaltopia backend calls this service with data, service renders beautiful templates and sends emails via Resend. ## πŸ“ Project Structure ``` β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ components/ # React UI components β”‚ β”œβ”€β”€ templates/ # Email template components β”‚ β”œβ”€β”€ lib/ # Utilities and services β”‚ β”‚ β”œβ”€β”€ config.ts # Environment configuration β”‚ β”‚ β”œβ”€β”€ logger.ts # Structured logging β”‚ β”‚ β”œβ”€β”€ validation.ts # Input validation schemas β”‚ β”‚ └── resendService.ts # Email service β”‚ └── ... β”œβ”€β”€ docs/ # Documentation β”œβ”€β”€ server.ts # Production API server β”œβ”€β”€ docker-compose.yml # Docker configuration └── .env.example # Environment template ``` ## πŸ”§ Configuration ### Required Environment Variables ```env RESEND_API_KEY=re_your_api_key_here FROM_DOMAIN=yaltopia.com ``` ### Optional Configuration ```env FROM_EMAIL=noreply@yaltopia.com NODE_ENV=production PORT=3001 RATE_LIMIT_MAX=20 RATE_LIMIT_WINDOW_MS=900000 CORS_ORIGIN=https://yaltopia.com LOG_LEVEL=info ``` ## πŸ›‘οΈ Security Features - **Input Validation**: Zod schemas for all API inputs - **Rate Limiting**: Configurable email sending limits (default: 10/15min) - **Security Headers**: Helmet.js with CSP, HSTS, XSS protection - **CORS Protection**: Configurable origin restrictions - **Privacy Protection**: Email/IP masking in logs - **Error Handling**: No sensitive data in error responses ## πŸ“Š Monitoring ### Health Check ```bash curl http://localhost:3001/health # Returns: {"status": "healthy", "timestamp": "..."} ``` ### Structured Logging ```json { "level": "info", "message": "Email sent successfully", "timestamp": "2026-03-12T10:00:00.000Z", "meta": { "templateId": "invitation", "to": "u***@example.com", "messageId": "abc123" } } ``` ## πŸ“š Documentation - **[API Reference](docs/API.md)** - Complete API documentation with examples - **[Deployment Guide](docs/DEPLOYMENT.md)** - Production deployment instructions - **[Security Guide](docs/SECURITY.md)** - Security features and best practices ## πŸš€ Deployment Options ### Docker (Recommended) ```bash docker-compose up -d ``` ### Cloud Platforms - **Vercel**: `vercel --prod` - **Railway**: `railway up` - **Heroku**: `git push heroku main` - **AWS/GCP**: Standard Node.js deployment ### Manual Node.js ```bash npm run build npm start ``` ## πŸ§ͺ Development Scripts ```bash npm run dev # Start frontend development npm run server:dev # Start backend with hot reload npm run build # Build for production npm run type-check # Validate TypeScript npm run lint # Run ESLint npm run validate # Full validation (lint + build) npm start # Start production server ``` ## πŸ” Troubleshooting ### Common Issues **"Domain not verified"** - Verify your domain in [Resend dashboard](https://resend.com/domains) - Add SPF record: `v=spf1 include:_spf.resend.com ~all` **"Rate limit exceeded"** - Check current limits: `curl http://localhost:3001/api` - Adjust `RATE_LIMIT_MAX` in environment variables **"Email not delivered"** - Check Resend logs in dashboard - Verify recipient email address - Check spam folder ## 🀝 Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Run tests: `npm run validate` 5. Submit a pull request ## πŸ“„ License Private - Internal use only --- **Ready for production with enterprise-grade security and reliability!** πŸš€ For detailed documentation, see the [docs](docs/) folder.