Email Templates¶
R Commerce uses customizable email templates for all customer and admin notifications. This guide covers available templates, variables, customization, and testing.
Overview¶
Email templates are:
- HTML and text - Multi-part emails for all clients
- Templating engine - Handlebars syntax for dynamic content
- Multi-language - Support for localization
- Customizable - Override default templates
Available Email Templates¶
Customer Notifications¶
| Template | Description | Trigger |
|---|---|---|
order_confirmation |
Order placed confirmation | Order created |
order_shipped |
Shipping notification | Fulfillment created |
order_delivered |
Delivery confirmation | Order delivered |
order_cancelled |
Order cancellation | Order cancelled |
order_refund |
Refund notification | Refund processed |
payment_receipt |
Payment confirmation | Payment captured |
payment_failed |
Failed payment alert | Payment failed |
account_created |
Welcome email | Customer registered |
password_reset |
Password reset link | Reset requested |
abandoned_cart |
Cart recovery | Cart abandoned (24h) |
Admin Notifications¶
| Template | Description | Trigger |
|---|---|---|
admin_order_notification |
New order alert | Order created |
admin_low_stock |
Low inventory alert | Stock below threshold |
admin_payment_dispute |
Chargeback/dispute alert | Dispute created |
admin_daily_summary |
Daily sales report | Daily cron |
Subscription Notifications¶
| Template | Description | Trigger |
|---|---|---|
subscription_created |
Subscription confirmation | Subscription started |
subscription_renewal |
Upcoming renewal notice | 3 days before renewal |
subscription_payment_failed |
Failed renewal payment | Renewal payment failed |
subscription_cancelled |
Cancellation confirmation | Subscription cancelled |
subscription_expired |
Subscription ended | Subscription expired |
Dunning Management¶
| Template | Description | Trigger |
|---|---|---|
dunning_retry_1 |
First payment retry notice | First retry attempt |
dunning_retry_2 |
Second payment retry notice | Second retry attempt |
dunning_final |
Final notice before cancellation | Final retry attempt |
Template Variables¶
Common Variables¶
All templates have access to:
Order Templates¶
Customer Templates¶
Payment Templates¶
Subscription Templates¶
Customizing Templates¶
Template Storage¶
Templates are stored in:
/etc/rcommerce/templates/ # System templates
/opt/rcommerce/templates/ # Custom templates (FreeBSD)
/var/lib/rcommerce/templates/ # Custom templates (Linux)
./templates/ # Development
Template Structure¶
Each template has three files:
templates/
├── order_confirmation/
│ ├── subject.hbs # Email subject
│ ├── html.hbs # HTML body
│ └── text.hbs # Plain text body
Creating Custom Templates¶
-
Create template directory:
-
Create subject template:
-
Create HTML template:
-
Create text template:
Template Configuration¶
Configure template location in config.toml:
[notifications.email]
template_dir = "/var/lib/rcommerce/templates"
default_from = "noreply@yourstore.com"
reply_to = "support@yourstore.com"
# Enable template auto-reload (development)
auto_reload = false
# Template cache TTL
cache_ttl = 3600
Template Inheritance¶
Create base templates for common elements:
Use partials:
Testing Templates¶
CLI Testing¶
Test templates with sample data:
# Test with default sample data
rcommerce template test order_confirmation
# Test with custom data file
rcommerce template test order_confirmation --data test_order.json
# Output to file
rcommerce template test order_confirmation --output test_email.html
# Send test email
rcommerce template test order_confirmation --send-to admin@example.com
Sample Data File¶
{
"order": {
"order_number": "1001",
"status": "confirmed",
"total": "99.99",
"currency": "USD",
"customer": {
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com"
},
"line_items": [
{
"name": "Premium T-Shirt",
"quantity": 2,
"price": "49.99",
"total": "99.98"
}
]
},
"store": {
"name": "My Store",
"url": "https://mystore.com"
}
}
Preview Server¶
Run a local preview server:
# Start preview server
rcommerce template preview
# Access at http://localhost:3001/preview/order_confirmation
Email Testing Tools¶
Test email rendering:
# Send to Litmus/Email on Acid
rcommerce template test order_confirmation --litmus
# Check spam score
rcommerce template test order_confirmation --spam-check
# Validate HTML
rcommerce template test order_confirmation --validate
Template Helpers¶
Built-in Helpers¶
Custom Helpers¶
Register custom helpers in configuration:
[notifications.email.helpers]
# Define custom helpers
loyalty_tier = "{{#if (gte customer.total_spent 1000)}}Gold{{else}}Silver{{/if}}"
Localization¶
Multi-language Templates¶
Create language-specific templates:
templates/
├── order_confirmation/
│ ├── en/
│ │ ├── subject.hbs
│ │ ├── html.hbs
│ │ └── text.hbs
│ ├── de/
│ │ ├── subject.hbs
│ │ ├── html.hbs
│ │ └── text.hbs
│ └── zh/
│ ├── subject.hbs
│ ├── html.hbs
│ └── text.hbs
Language Selection¶
Language is determined by:
- Customer's preferred language
- Order's locale
- Store default language
Best Practices¶
Email Design¶
- Use inline styles - Many clients block
<style>tags - Table-based layouts - Better email client support
- 600px max width - Standard email width
- Alt text for images - Accessibility and image blocking
- Plain text version - Always include text template
Template Maintenance¶
- Version control - Track template changes in Git
- Test before deploy - Always test template changes
- Monitor deliverability - Track bounce/spam rates
- A/B testing - Test different template versions
Security¶
- Escape variables - Prevent XSS in emails
- Validate URLs - Ensure all links are valid
- No sensitive data - Don't include passwords or tokens
Troubleshooting¶
Template Not Found¶
Solutions:
- Check template directory path
- Verify template files exist
- Check file permissions
Variable Not Rendering¶
Solutions:
- Check available variables in documentation
- Use
{{log order}}to debug - Verify data is passed to template
Email Rendering Issues¶
Solutions:
- Test with multiple email clients
- Use email testing service (Litmus, Email on Acid)
- Check inline CSS
- Validate HTML