Appearance
Email Infrastructure Backend Implementation
Architecture
Email functionality is split between two specialized services:
- Resend: Transactional email delivery (high reliability)
- Brevo: Marketing email management (subscriber lists, campaigns)
Service Implementation
ResendService (app/services/resend_service.ts)
typescript
export class ResendService {
static async sendWelcomeEmail(email: string): Promise<void>
static async sendPasswordReset(email: string, token: string): Promise<void>
static async sendEventNotification(email: string, event: Event): Promise<void>
}Features:
- High-deliverability transactional emails
- Template rendering with Edge.js
- Automatic retry logic
- Open/click tracking
BrevoService (app/services/brevo_service.ts)
typescript
export class BrevoService {
static async addSubscriber(email: string, listId: string): Promise<void>
static async removeSubscriber(email: string, listId: string): Promise<void>
static async sendCampaign(campaignId: string, recipients: string[]): Promise<void>
}Features:
- Subscriber list management
- Campaign creation and sending
- Segmentation and targeting
- Analytics and reporting
Email Templates
Template Structure
apps/server/resources/views/emails/
├── welcome.edge # User welcome email
├── password-reset.edge # Password reset email
├── event-notification.edge # Event updates
├── newsletter.edge # Newsletter template
└── layouts/
└── base.edge # Base email layoutTemplate Features
- Responsive design for mobile/desktop
- Consistent Jubiloop branding
- Variable substitution for dynamic content
- GDPR-compliant unsubscribe links
- Analytics tracking pixels
Example Template
html
<!-- welcome.edge -->
@layout('emails/layouts/base') @section('content')
<h1>Welcome to Jubiloop!</h1>
<p>Hi {{ user.name }},</p>
<p>Thank you for joining Jubiloop. We're excited to help you plan amazing events!</p>
<div class="cta">
<a href="{{ appUrl }}/dashboard" class="button">Get Started</a>
</div>
@endsectionEnvironment Configuration
Required Environment Variables
bash
# Resend (Transactional)
RESEND_API_KEY=your_resend_api_key
RESEND_FROM_NAME=Jubiloop Team
RESEND_FROM_EMAIL=noreply@jubiloop.ca
# Brevo (Marketing)
BREVO_API_KEY=your_brevo_api_key
BREVO_NEWSLETTER_SUBSCRIBER_LIST_ID=your_list_idPer-Environment Settings
- Development: Dev API keys, dev sender addresses
- QA: QA API keys, test recipient lists
- Production: Production API keys, verified domains
Integration Points
Newsletter Subscription Feature
typescript
// Uses both services
await BrevoService.addSubscriber(email, listId) // Add to marketing list
await ResendService.sendWelcomeEmail(email) // Send welcome emailAuthentication System
typescript
// Password reset flow
await ResendService.sendPasswordReset(email, resetToken)
// Welcome new users
await ResendService.sendWelcomeEmail(user.email)Future Event System
typescript
// Event notifications
await ResendService.sendEventNotification(attendee.email, eventData)
// Event marketing
await BrevoService.sendCampaign(campaignId, attendeeEmails)Security & Compliance
Data Protection
- GDPR Compliance: Unsubscribe links in all marketing emails
- Data Encryption: Secure API communication with TLS
- Access Controls: API keys managed through environment variables
- Audit Logging: Track all email operations for compliance
Security Measures
- Rate Limiting: Prevent abuse of email endpoints
- Input Validation: Sanitize all email addresses and content
- Template Security: Prevent XSS in email templates
- Error Handling: Graceful failure without exposing sensitive data
Monitoring & Analytics
Resend Metrics
- Delivery rate (percentage delivered successfully)
- Open rate (tracking pixel-based)
- Click rate (tracked links)
- Bounce rate (failed deliveries)
- Spam complaints
Brevo Metrics
- Subscriber growth over time
- Campaign engagement rates
- List health (bounce/complaint rates)
- Geographic distribution
- Unsubscribe rates
Health Monitoring
bash
# Test Resend connectivity
curl -H "Authorization: Bearer $RESEND_API_KEY" \
https://api.resend.com/domains
# Test Brevo connectivity
curl -H "Authorization: Bearer $BREVO_API_KEY" \
https://api.brevo.com/v3/contactsError Handling
Common Failure Scenarios
- API Rate Limits: Implement exponential backoff
- Invalid Recipients: Validate email addresses before sending
- Template Errors: Graceful fallback to plain text
- Service Outages: Queue emails for retry
Debugging
bash
# Check email service logs
docker logs server | grep -i email
# Test template compilation
# (via AdonisJS REPL or test endpoints)
# Verify API credentials
# (health check endpoints)Performance Considerations
Optimization Strategies
- Template Caching: Compile templates once, reuse
- Batch Operations: Send multiple emails efficiently
- Async Processing: Queue emails for background processing
- Connection Pooling: Reuse HTTP connections to email APIs
Scalability
- Service Separation: Resend/Brevo handle scaling
- Queue System: Redis-based email queue for high volume
- Retry Logic: Exponential backoff for failed deliveries
- Monitoring: Track performance metrics and alerts
Future Enhancements
Planned Improvements
- Email Queue System: Async processing with Redis
- Template Management: Dynamic template updates without deployments
- A/B Testing: Email variant testing for optimization
- Advanced Segmentation: Behavioral targeting based on user actions
- Webhook Integration: Real-time delivery status updates
Integration Opportunities
- Event Management: Automated event reminder emails
- User Notifications: In-app to email notification fallback
- Analytics Integration: Custom email tracking in application analytics
- Multi-Provider Support: Fallback email providers for reliability