Newsletter Subscription System Design
A self-hosted mailing list for Almanack using Listmonk, PurelyMail for SMTP, and a margin box + static page for subscription.
Overview
Readers can subscribe to receive news of new Almanack articles by email. The system uses Listmonk (self-hosted) for list management and PurelyMail for outbound delivery. No third-party SaaS touches the subscriber list.
Three pieces:
- Listmonk + Postgres in the existing docker-compose stack
- Caddy routing — public subscription endpoint at
list.almnck.com, admin UI on Tailscale only - Subscription UI — an interactive margin box (JS) with a plain
/subscribe/page as no-JS fallback
Data Flow
Reader types email
→ form POSTs to list.almnck.com/api/public/subscription
→ Caddy rate-limits (5 req/min/IP), proxies to Listmonk
→ Listmonk writes to Postgres
→ Listmonk sends double opt-in email via PurelyMail SMTP
→ Reader confirms → subscribed
No Almanack API involvement. No API keys exposed client-side. Listmonk handles subscriber state; Caddy and a honeypot field handle abuse prevention.
Docker Compose Changes
New Services
Two new services added to assets/system/docker-compose.yml:
listmonk-db:
image: docker.io/library/postgres:16-alpine
environment:
- POSTGRES_USER=listmonk
- POSTGRES_PASSWORD_FILE=/run/secrets/listmonk_db_pass
- POSTGRES_DB=listmonk
volumes:
- /var/local/listmonk/pgdata:/var/lib/postgresql/data:Z
networks:
- listmonk-internal
secrets:
- listmonk_db_pass
restart: unless-stopped
listmonk:
image: docker.io/listmonk/listmonk:latest
depends_on:
- listmonk-db
environment:
- LISTMONK_app__address=0.0.0.0:9000
- LISTMONK_db__host=listmonk-db
- LISTMONK_db__port=5432
- LISTMONK_db__user=listmonk
- LISTMONK_db__password=<from secret/env>
- LISTMONK_db__database=listmonk
- LISTMONK_app__admin_username=<from secret/env>
- LISTMONK_app__admin_password=<from secret/env>
ports:
- "<tailscale-ip>:9000:9000" # Admin UI — Tailscale only
expose:
- "9000"
networks:
- caddy
- listmonk-internal
labels:
caddy: list.almnck.com
caddy.reverse_proxy: "{{upstreams 9000}}"
restart: unless-stopped
Where <tailscale-ip> is the Tailscale address of the production host
(the production host’s Tailscale address, resolved to its 100.x.x.x IP).
New Network
networks:
caddy:
driver: bridge
listmonk-internal:
driver: bridge
Postgres lives only on listmonk-internal — not reachable from Caddy or the
internet. Listmonk joins both networks: listmonk-internal to reach Postgres,
caddy so the reverse proxy can reach it.
Secrets
secrets:
listmonk_db_pass:
file: /var/local/listmonk/secrets/db_password
Persistent Data
All Listmonk data under /var/local/listmonk/:
/var/local/listmonk/
├── pgdata/ # Postgres data directory
└── secrets/
└── db_password # Postgres password file
Caddy: Custom Image with Rate Limiting
Caddy’s rate_limit is a plugin (mholt/caddy-ratelimit), not built in. We
build a small custom image:
Dockerfile
# assets/system/Dockerfile.caddy
FROM docker.io/library/caddy:builder AS builder
RUN xcaddy build --with github.com/mholt/caddy-ratelimit
FROM docker.io/library/caddy:latest
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
Update the caddy service in docker-compose to build: from this Dockerfile
instead of using the stock image.
Routing
Caddy labels on the listmonk service restrict public access to only the
subscription API and opt-in/unsubscribe pages. Everything else (admin UI,
private API) returns 404.
Effective configuration for list.almnck.com:
list.almnck.com {
# Rate limit subscription endpoint: 5 requests/minute per IP
@subscription path /api/public/subscription
rate_limit @subscription {
zone subscription_zone {
key {remote_host}
events 5
window 1m
}
}
# Allow public API and opt-in/unsubscribe pages
@public {
path /api/public/*
path /subscription/*
}
reverse_proxy @public listmonk:9000
# Block everything else
respond 404
}
This is expressed via Caddy Docker Proxy labels on the listmonk service.
Admin UI Access
The admin UI is accessible only via the Tailscale address:
http://<tailscale-host>:9000
The ports binding ensures the admin port is only reachable on the Tailscale
interface. Caddy never proxies admin routes — the respond 404 catch-all
blocks them on list.almnck.com.
SMTP Configuration
Listmonk sends mail via PurelyMail’s SMTP. Configure in Listmonk’s admin UI (Settings → SMTP):
| Field | Value |
|---|---|
| Host | smtp.purelymail.com |
| Port | 587 |
| Auth | LOGIN |
| Username | (PurelyMail SMTP username) |
| Password | (PurelyMail SMTP password) |
| TLS | STARTTLS |
| From | list@almnck.com (or similar) |
PurelyMail must have the sending domain (almnck.com) configured with
appropriate SPF/DKIM records.
Margin Box: Interactive Subscribe Form
Editorial Content
editorial/margin-boxes/subscribe/
├── margin-box.md
└── assets/
└── subscribe.js
margin-box.md
---
type: editorial
placement: right-bottom
priority: normal
pages: [articles]
weight: 70
active: true
interactive: subscribe
---
**Get the Almanack by Post**
News of new articles, delivered by electrical mail.
[Subscribe →](/subscribe/)
The static markdown content includes a link to the /subscribe/ page — this
is the baseline experience. The interactive module enhances it.
Interactive Module: subscribe.js
export const meta = {
name: 'subscribe',
description: 'Inline newsletter subscription form',
version: '1.0.0'
};
export function setup(container) {
// 1. Get whimsical name from identity system
const identity = window.AlmanackIdentity;
const prefillName = identity?.getName?.() || '';
// 2. Replace static content with form
container.innerHTML = `
<p><strong>Get the Almanack by Post</strong></p>
<p>News of new articles, delivered by electrical mail.</p>
<form class="subscribe-form" novalidate>
<label for="subscribe-name">Name</label>
<input id="subscribe-name" name="name" type="text"
value="${prefillName}">
<label for="subscribe-email">Email</label>
<input id="subscribe-email" name="email" type="email"
required placeholder="you@example.com">
<input name="hp" tabindex="-1" autocomplete="off"
aria-hidden="true"
style="position:absolute;left:-9999px">
<button type="submit">Subscribe</button>
</form>
`;
const form = container.querySelector('.subscribe-form');
const nameInput = container.querySelector('[name="name"]');
const originalName = prefillName;
form.addEventListener('submit', async (e) => {
e.preventDefault();
// Honeypot check
if (form.querySelector('[name="hp"]').value) return;
const email = form.querySelector('[name="email"]').value;
const name = nameInput.value;
// Disable button (debounce)
const btn = form.querySelector('button');
btn.disabled = true;
btn.textContent = 'Sending…';
try {
const resp = await fetch('https://list.almnck.com/api/public/subscription', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email,
name,
list_uuids: ['<LIST-UUID>']
})
});
if (resp.ok) {
// Track if they changed their name
if (name && name !== originalName) {
localStorage.setItem('almanack:preferred-name', name);
}
container.innerHTML = `
<p><strong>Check your post</strong></p>
<p>We've sent a confirmation to <em>${email}</em>.
Click the link to complete your subscription.</p>
`;
} else if (resp.status === 429) {
btn.textContent = 'Too many attempts — try again shortly';
setTimeout(() => {
btn.disabled = false;
btn.textContent = 'Subscribe';
}, 30000);
} else {
throw new Error(resp.status);
}
} catch {
btn.textContent = 'Something went wrong — try again';
setTimeout(() => {
btn.disabled = false;
btn.textContent = 'Subscribe';
}, 5000);
}
});
}
Dev Symlinks
mkdir -p assets/margin-boxes/subscribe
ln -sf ../../../editorial/margin-boxes/subscribe/assets/subscribe.js \
assets/margin-boxes/subscribe/subscribe.js
No-JS Fallback: /subscribe/ Page
Editorial Content
editorial/pages/subscribe/
└── page.md
---
title: Subscribe
slug: subscribe
---
**Get the Almanack by Post**
News of new articles, delivered by electrical mail.
Template
The subscribe page template renders a plain HTML form that POSTs directly to Listmonk. No JavaScript required.
<form action="https://list.almnck.com/api/public/subscription" method="POST">
<input type="hidden" name="list_uuids" value="<LIST-UUID>">
<label for="sub-name">Name (optional)</label>
<input id="sub-name" name="name" type="text">
<label for="sub-email">Email</label>
<input id="sub-email" name="email" type="email" required>
<!-- honeypot -->
<input name="hp" tabindex="-1" autocomplete="off"
aria-hidden="true" style="position:absolute;left:-9999px">
<button type="submit">Subscribe</button>
</form>
On success, Listmonk redirects to /subscribe/?thanks=1. The template detects
the query parameter and shows a confirmation message instead of the form.
Note: The honeypot field is present in both the JS and no-JS forms. Bots
that auto-fill hidden fields will be silently discarded by client-side JS (in
the margin box) or ignored by Listmonk (which doesn’t process the hp field).
The honeypot is a client-side check only; server-side abuse prevention comes
from Caddy’s rate limiter.
<noscript> Link in Base Template
A subscribe link appears for no-JS readers after the article body:
<noscript>
<div class="noscript-subscribe">
<a href="/subscribe/">Get the Almanack by post →</a>
</div>
</noscript>
Abuse Prevention Summary
| Layer | Mechanism | Catches |
|---|---|---|
| Caddy | Rate limit: 5 req/min/IP on /api/public/subscription |
Floods, brute force |
| Form (both) | Honeypot hidden field | Dumb bots, scrapers |
| JS form | Button disable for 30s after submit | Impatient double-clicks |
| Listmonk | Double opt-in email | Fake/unwanted signups |
| Admin | Tailscale-only access | Unauthorized admin access |
Experience Summary
| Reader | What they see |
|---|---|
| JS enabled | Inline margin box form, pre-filled whimsical name, AJAX submit, inline confirmation |
| JS disabled | <noscript> link → /subscribe/ page → plain form POST → redirect confirmation |
| Screen reader | Both paths fully labelled, honeypot has aria-hidden="true" |
Name Preference Flow
The margin box pre-fills the name field with the reader’s whimsical identity
name (from window.AlmanackIdentity.getName()). If the reader changes the
name before submitting:
- The new name is sent to Listmonk as the subscriber name
- The preference is saved to
localStorageatalmanack:preferred-name - Future UI can reference this — e.g. “Would you prefer we call you X?”
If they leave the whimsical name unchanged, Listmonk gets the whimsical name as the subscriber name, which is in keeping with the identity system’s spirit.
Setup Checklist
- Create
/var/local/listmonk/directory tree on production host - Generate and store Postgres password in
/var/local/listmonk/secrets/db_password - Build custom Caddy image with rate-limit plugin
- Add services to docker-compose, deploy
- Run
listmonk --installto initialise the database - Access admin at
http://<tailscale-host>:9000, configure: - SMTP settings (PurelyMail)
- Create a mailing list, note its UUID
- Customise opt-in and notification templates
- Set post-subscription redirect to
/subscribe/?thanks=1 - Add DNS record:
list.almnck.com→ production host - Replace
<LIST-UUID>placeholders in margin box and subscribe page - Create editorial content (
margin-box.md,page.md) - Create dev symlinks for margin box assets
make sync && make build