Features
Email System
How email delivery works in Time Capsule
Email System
Time Capsule uses SendGrid for reliable email delivery with custom HTML templates.
How It Works
Scheduled Delivery
When you create a capsule:
- Capsule Created - Saved to database
- Email Scheduled - Celery task created for unlock date
- Wait Period - Task waits until unlock date
- Email Sent - Recipient receives notification
- Status Updated -
sent_attimestamp recorded
Architecture
Create Capsule → Celery Task → Redis Queue → Wait → SendGrid → RecipientEmail Components
SendGrid Integration
Time Capsule uses SendGrid API for:
- Reliable delivery
- Custom HTML templates
- Delivery tracking
- High deliverability rates
Configuration:
EMAIL_HOST_PASSWORD = 'your_sendgrid_api_key'
DEFAULT_FROM_EMAIL = 'noreply@yourdomain.com'Celery Tasks
Asynchronous task handling:
send_capsule_template_email- Main email tasksend_simple_email- Test email task- Scheduled execution at unlock date
- Retry logic on failures
Redis Queue
Message broker for Celery:
- Stores scheduled tasks
- Manages task queue
- Enables distributed processing
If Redis is unavailable, emails are sent immediately as a fallback
Email Template
Custom HTML Design
Emails include:
- Header - Time Capsule branding
- Title - Capsule title in large text
- Content - Full message content
- CTA Button - Link to view online
- Footer - Timestamp and branding
Template Variables
{
'capsule_title': 'My First Capsule',
'capsule_content': 'Message content here...',
'capsule_url': 'https://yourdomain.com/capsule_detail/1/'
}Email Subject
🎁 Your Time Capsule '{title}' is Unlocked!Fallback System
With Redis (Preferred)
if is_redis_available():
send_capsule_template_email.apply_async(
args=[email, title, content, url],
eta=unlock_date
)Without Redis (Fallback)
else:
send_capsule_template_email_sync(
email, title, content, url
)Without Redis, emails are sent immediately instead of being scheduled
Manual Email Sending
Admins can manually trigger emails:
- Navigate to capsule detail page
- Click "Send Email" button
- Email sent immediately to recipient
Use Cases:
- Testing email delivery
- Resending failed emails
- Sending before unlock date
Email Testing
Admin-only test interface at /test-email/:
- Enter test email address
- Submit form
- Receive sample capsule email
Test Email Contains:
- Sample title: "My First Time Capsule"
- Sample content with placeholder text
- Link to homepage
Delivery Status
Tracking
The Recipient model tracks:
{
"email": "recipient@example.com",
"sent_at": "2024-01-15 10:30:00" # null until sent
}Verification
Check if email was sent:
sent_atis null → Not sent yetsent_athas timestamp → Sent successfully
Error Handling
Common Issues
SendGrid API Error:
- Check API key is valid
- Verify sender email is verified in SendGrid
- Check SendGrid account status
Redis Connection Error:
- Falls back to immediate send
- Check Redis URL configuration
- Verify Redis server is running
Email Not Received:
- Check spam/junk folder
- Verify recipient email is correct
- Check SendGrid activity logs
Logging
All email operations are logged:
print(f"Email sent successfully to {recipient_email}")
print(f"Failed to send email: {error_message}")Best Practices
For Production:
- Use Redis for scheduled delivery
- Verify sender domain in SendGrid
- Monitor SendGrid dashboard
- Set up email authentication (SPF, DKIM)
- Keep API keys secure