AWS Builder Center
Integrating Amazon SES SMTP with a Django Application

Integrating Amazon SES SMTP with a Django Application

Learn how to integrate Amazon SES SMTP with a Django application to build a flexible and configurable email system. This article covers SMTP configuration, SES credentials, TLS/SSL setup, connection testing, sending limits, and managing multiple email providers directly from a Django CRM.

Integrating Amazon SES SMTP with a Django Application

SES SMTP with a Django CRM

I recently added a configurable SMTP system to my Django CRM so that email providers can be managed from the application instead of hard-coding email settings in settings.py.
The system supports:
· Amazon SES
· Gmail
· Custom SMTP providers
· Multiple SMTP configurations
· Active/inactive SMTP accounts
· TLS / SSL configuration
· Configurable daily sending limits
· SMTP connection testing

Amazon SES Integration

For Amazon SES, my Django application connects through the SES SMTP interface.
For example, for the AWS Mumbai region:
Provider: Amazon SES
Host: email-smtp.ap-south-1.amazonaws.com
Port: 587
TLS: Enabled
SSL: Disabled
The username and password are Amazon SES SMTP credentials, which are different from normal AWS access keys.
In Django, I use a model to store the SMTP configuration:
class SMTPConfiguration(models.Model):
    name = models.CharField(max_length=100)
    provider = models.CharField(max_length=20)
    host = models.CharField(max_length=255)
    port = models.PositiveIntegerField(default=587)
    username = models.CharField(max_length=255)
    password = models.CharField(max_length=255)

    use_tls = models.BooleanField(default=True)
    use_ssl = models.BooleanField(default=False)

    from_email = models.EmailField()
    from_name = models.CharField(max_length=100, blank=True)

    daily_send_limit = models.PositiveIntegerField(default=500)
    is_active = models.BooleanField(default=False)
I also added a connection-testing service using Python's smtplib:
server = smtplib.SMTP(host, port, timeout=10)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
This allows the administrator to click Test Connection before activating the SMTP account.

Important Amazon SES Setup

Before sending emails, the sender identity must be verified in Amazon SES.
If the SES account is still in the sandbox, recipient addresses also need to be verified. Moving the account out of the sandbox removes that recipient restriction, subject to the account's sending limits.
The overall flow is:
Django CRM
    ↓
SMTP Configuration
    ↓
Amazon SES SMTP Endpoint
    ↓
Authentication
    ↓
Amazon SES
    ↓
Recipient
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article