Skip to main content

Email

Overview

SpeedPy uses django-post_office as the email backend, with Celery for async delivery. Emails are composed using Django templates and sent via post_office.mail.send().

Configuration

In project/settings.py:

EMAIL_BACKEND = "post_office.EmailBackend"
POST_OFFICE = {
"BACKENDS": {
"default": "django.core.mail.backends.console.EmailBackend",
},
"DEFAULT_PRIORITY": "now",
"CELERY_ENABLED": True,
}

The email connection is configured via the EMAIL_URL environment variable:

# SMTP example
EMAIL_URL=smtp://user:password@smtp.example.com:587/?tls=True

# Console (development)
# Leave EMAIL_URL empty or unset

Sending Emails

Use Django's render_to_string for templates and post_office.mail.send() for delivery:

from django.template.loader import render_to_string
from django.conf import settings
from post_office import mail

context = {
'team_name': 'My Team',
'invite_url': 'https://example.com/invite/abc123',
}
subject = "You've been invited to join My Team"
html_message = render_to_string("emails/team_invitation.html", context=context)

mail.send(
'recipient@example.com',
settings.DEFAULT_FROM_EMAIL,
html_message=html_message,
subject=subject,
priority='now',
)
info

Do not use post_office's built-in template system. Instead, use Django's render_to_string to prepare the HTML message.

Email Templates

Place email templates in templates/emails/. SpeedPy includes templates for:

  • Team invitations
  • Role change notifications

Backend Options

Console (Development)

The default backend prints emails to the console — useful for development:

"default": "django.core.mail.backends.console.EmailBackend",

SMTP

For any SMTP provider, set EMAIL_URL:

EMAIL_URL=smtp://user:password@smtp.example.com:587/?tls=True

AWS SES

SpeedPy includes django-ses for Amazon SES. To enable it, change the post_office backend:

POST_OFFICE = {
"BACKENDS": {
"default": "django_ses.SESBackend",
},
...
}

And configure your SES credentials:

AWS_SES_ACCESS_KEY_ID=your-key
AWS_SES_SECRET_ACCESS_KEY=your-secret

SES region settings:

AWS_SES_REGION_NAME = "eu-central-1"
AWS_SES_REGION_ENDPOINT = "email.eu-central-1.amazonaws.com"
AWS_SES_AUTO_THROTTLE = 0.5
DEFAULT_FROM_EMAIL = env.str("DEFAULT_FROM_EMAIL", default="admin@example.com")