📄 Email marketing platforms – Self-Hosted HTTP-to-SMTP Email API

Webmailer is a lightweight, open-source Django-based HTTP-to-SMTP email microservice designed to offer a simple and flexible alternative to providers like SendGrid or Mailgun — but fully hostable on your own infrastructure.

It exposes a clean, minimal HTTP API endpoint that accepts email parameters via POST and dispatches messages using your own SMTP server, with full logging and delivery status tracking.

This project is part of the broader Email-marketing-platforms initiative, where we aim to build a suite of open and self-hostable tools for sending and managing email campaigns and transactional messaging — without vendor lock-in.


🔧 Features

  • Send emails via RESTful API using application/json
  • Supports both plain text and HTML bodies
  • Built-in List-Unsubscribe header generation
  • One email per request (ensures accurate delivery status per recipient)
  • Stores full message log and SMTP status (sent, failed, etc.)
  • IP whitelisting for secure API access
  • Easy to deploy with Apache + mod_wsgi
  • Python 2.7 and Django 1.8 compatible (for legacy environments)

🔌 API Endpoint

POST /api/send-email/

Payload (JSON):

{
  "client_id": "your-app",
  "from_email": "noreply@example.com",
  "to_email": "user@example.net",
  "subject": "Welcome!",
  "text_body": "Hello user, welcome to our service.",
  "html_body": "

Hello user, welcome to our service.

", "unsubscribe_url": "https://example.com/unsubscribe?id=123" }

Response:

{
  "status": "sent",
  "id": 10123
}

🛠 Use Cases

  • Self-hosted email delivery for CRM or SaaS applications
  • Replacement for SendGrid/Mailgun when using your own SMTP
  • Email relay API for internal apps or staging environments
  • Educational or test setup for building reliable SMTP-based delivery

📁 Structure

This is one of several tools being developed under Email-marketing-platforms. Future components may include:

  • Bounce handler / webhook parser
  • Template & contact manager
  • Admin dashboard for delivery logs
  • Cron-based campaign batch sender
  • Mail merge and personalization tools

Each tool can be linked from this central repository, or optionally bundled together depending on integration needs.


📦 Planned Extensions

  • Token-based API authentication
  • Rate limiting per IP
  • Multiple SMTP relay backends
  • Stats dashboard (success, bounce, open rate)
  • DKIM/SPF validation helper

1. System setup

sudo apt update
sudo apt install apache2 libapache2-mod-wsgi python2.7 python-pip
sudo pip install virtualenv

2. Clone and prepare project

git clone https://github.com/OnlineSolutionsGroupBV/Email-marketing-platforms.git
cd Email-marketing-platforms
virtualenv venv --python=python2.7
source venv/bin/activate
pip install django==1.8

3. Django project configuration

In config/settings.py:
ALLOWED_HOSTS = ['webmailer.example.com', '127.0.0.1', '176.9.149.230']

ALLOWED_SENDER_IPS = ['127.0.0.1', '176.9.149.230', 'YOUR_CLIENT_SERVER_IP']

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

4. Prepare database

python manage.py migrate
python manage.py collectstatic
python manage.py createsuperuser

5. Apache configuration

Example /etc/apache2/sites-available/webmailer.conf:
<VirtualHost *:80>
    ServerName webmailer.example.com

    WSGIScriptAlias / /home/admin/Email-marketing-platforms/config/wsgi.py
    WSGIDaemonProcess webmailer python-path=/home/admin/Email-marketing-platforms
    WSGIProcessGroup webmailer

    Alias /static /home/admin/Email-marketing-platforms/static
    <Directory /home/admin/Email-marketing-platforms/static>
        Require all granted
    </Directory>

    <Directory /home/admin/Email-marketing-platforms/config>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>

6. Enable and restart Apache

sudo a2ensite webmailer
sudo a2enmod wsgi
sudo service apache2 restart

🔌 API Usage

Endpoint

POST http://webmailer.example.com/api/send-email/

Example JSON Payload

{
  "client_id": "example-app",
  "from_email": "noreply@example.com",
  "to_email": "test@domain.com",
  "subject": "Welcome to Webmailer",
  "text_body": "Hello, thank you for joining.",
  "html_body": "

Hello, thank you for joining.

", "unsubscribe_url": "https://example.com/unsubscribe?id=abc123" }

Response

{
  "status": "sent",
  "id": 10123
}

Example CURL request

curl -X POST http://webmailer.example.com/api/send-email/ \
  -H \"Content-Type: application/json\" \
  -d '{
    "client_id": "test",
    "from_email": "noreply@example.com",
    "to_email": "user@example.com",
    "subject": "Test Email",
    "text_body": "This is a test",
    "html_body": "

This is a test

", "unsubscribe_url": "https://example.com/unsubscribe?id=xyz" }'

Python (requests) example

import requests

payload = {
    \"client_id\": \"test\",
    \"from_email\": \"noreply@example.com\",
    \"to_email\": \"user@example.com\",
    \"subject\": \"Test Email\",
    \"text_body\": \"This is a test\",
    \"html_body\": \"

This is a test

\", \"unsubscribe_url\": \"https://example.com/unsubscribe?id=xyz\" } response = requests.post(\"http://webmailer.example.com/api/send-email/\", json=payload) print(response.status_code, response.json())

Comments