Backbone Email
๐ฆด Production-ready SMTP email service library with template support
Backbone Email is a focused email service library that provides reliable SMTP email functionality with advanced features like template sending, file attachments, and comprehensive error handling. Designed for production use with robust error handling and tracking capabilities.
๐ Table of Contents
๐ฏ Overview
Backbone Email provides a clean, efficient SMTP email service that handles all common email needs without the complexity of multiple provider abstractions. It's designed for production use with comprehensive error handling and template support.
Key Design Principles
- SMTP Focused: Optimized for reliable SMTP email delivery
- Template Ready: Built-in template rendering with Handlebars
- Production Ready: Robust error handling with retry mechanisms
- Async First: Full async/await support with tokio
- File Attachments: Support for multiple file types and sizes
๐ Features
๐ง Core Email Features
- SMTP Support: Traditional email servers with TLS/SSL support
- Template System: Built-in Handlebars template rendering
- File Attachments: Multiple file attachment support with type detection
- Rich Content: HTML, text, and multipart messages
- Recipient Management: To, CC, and BCC support
๐ก๏ธ Production-Ready
- Error Handling: Comprehensive error types with context
- Connection Testing: Pre-flight SMTP connection validation
- Retry Logic: Configurable retry mechanisms for failed deliveries
- Async Operations: Non-blocking email sending and receiving
๐ Message Capabilities
- Multiple Recipients: Send to multiple email addresses
- Custom Headers: Add custom SMTP headers
- Priority Levels: Set message priority (High, Normal, Low)
- Reply-To: Configure reply-to addresses
- Bulk Sending: Send multiple emails efficiently
๐ Usage
Quick Start
[]
= "2.0.0"
= { = "1.0", = ["full"] }
= { = "1.0", = ["derive"] }
= { = "1.0", = ["v4"] }
= { = "0.4", = ["serde"] }
Basic Email Sending
use ;
// Create SMTP email service
let email_service = new
.with_credentials
.with_tls
.build?;
// Create email message
let message = builder
.from
.to
.subject
.text
.html
.build?;
// Send email
let result = email_service.send.await?;
println!;
Template Sending
use ;
use HashMap;
// Create email service
let email_service = new
.with_credentials
.build?;
// Template data
let mut template_data = new;
template_data.insert;
template_data.insert;
// Send template email
let result = email_service.send_template.await?;
println!;
Email with Attachments
use ;
// Create email service
let email_service = new
.with_credentials
.build?;
// Create attachment
let attachment = builder
.filename
.content
.content_type
.build?;
// Send email with attachment
let message = builder
.from
.to
.subject
.text
.attachment
.build?;
let result = email_service.send.await?;
println!;
๐ง SMTP Configuration
Basic Configuration
use SmtpProvider;
// Simple SMTP configuration
let email_service = new
.with_credentials
.build?;
Advanced Configuration
use SmtpProvider;
// Advanced SMTP configuration with TLS and custom settings
let email_service = new
.with_credentials
.with_tls
.with_timeout
.with_connection_pool_size
.with_default_sender
.build?;
Common SMTP Providers
Gmail/Google Workspace
let email_service = new
.with_credentials
.with_tls
.build?;
Outlook/Office 365
let email_service = new
.with_credentials
.with_tls
.build?;
SendGrid
let email_service = new
.with_credentials
.with_tls
.build?;
๐ง Technical Details
Core Traits
EmailService Trait
Message Types
EmailMessage
EmailDeliveryReport
Error Handling
๐ Examples
1. Welcome Email Service
use ;
use HashMap;
async
2. Bulk Email Newsletter
use ;
async
3. Email Service Health Check
use EmailService;
async
๐ง Error Handling
Error Recovery
use ;
async
๐งช Testing
Unit Tests
# Run all backbone-email tests
# Run specific tests
Mock Testing
use ;
use HashMap;
๐ Configuration
Environment Variables
# SMTP Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=user@gmail.com
SMTP_PASSWORD=app_password
SMTP_USE_TLS=true
SMTP_DEFAULT_SENDER=notifications@company.com
YAML Configuration
# backbone-email configuration
email:
provider: "smtp"
smtp:
host: "${SMTP_HOST}"
port: ${SMTP_PORT}
username: "${SMTP_USERNAME}"
password: "${SMTP_PASSWORD}"
use_tls: ${SMTP_USE_TLS}
timeout: 30
connection_pool_size: 5
# Template settings
templates:
engine: "handlebars"
directory: "./templates"
# Default settings
defaults:
sender: "${SMTP_DEFAULT_SENDER}"
priority: "normal"
๐ Performance Considerations
Connection Pooling
// Reuse the email service instance
let email_service = new;
// Thread-safe usage across multiple tasks
for i in 0..100
๐ Version History
Current Version: 2.0.0
Features:
- โ SMTP email delivery with TLS support
- โ Handlebars template rendering
- โ File attachment support
- โ Connection testing and validation
- โ Comprehensive error handling
- โ Async/await support
- โ Builder pattern configuration
Breaking Changes from v1.x:
- Simplified to SMTP-only implementation
- Updated API to use builder patterns
- Enhanced error handling with context
- Removed multi-provider complexity
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Projects
- Backbone Core - Generic CRUD foundation
- Backbone CLI - Code generation tools
- Backbone Storage - File storage services
- Framework Documentation - Complete framework guide
๐ฆด Backbone Email - Simple, reliable SMTP email delivery
SMTP Focused โข Template Ready โข Production Ready