postal

by upstreamyard

Helm chartv0.1.6App 3.5.0MITVerified publisher

Postal, the open-source mail delivery platform for sending and receiving email (web interface and API, SMTP server, workers). Community chart by upstreamyard, not an official Postal chart.

About this chart

Postal Helm chart

Have any questions, feedback or need help (e.g. setup, hardened images, etc.)? Reach out to [email protected]

Helm chart for Postal, the open-source mail delivery platform for sending and receiving email: an alternative to Sendgrid, Mailgun or Postmark that you run yourself. It runs the web interface and HTTP API, the SMTP server and the workers, using Postal's official image ghcr.io/postalserver/postal.

Community chart by upstreamyard, not an official Postal chart. Postal is © Krystal Hosting Ltd and contributors, licensed under MIT.

Install

Postal needs MariaDB (see Requirements). Create the keys once and keep them: the signing key is published in your DKIM DNS record, so a new key breaks DKIM for the default return path domain.

openssl genrsa -out signing.key 2048
kubectl create secret generic postal-keys \
  --from-literal=secret-key="$(openssl rand -hex 64)" \
  --from-file=signing-key=signing.key

helm repo add upstreamyard https://upstreamyard.github.io/helm-charts
helm install postal upstreamyard/postal \
  --set postal.webHostname=postal.example.com \
  --set postal.existingSecret=postal-keys \
  --set database.host=your-mariadb \
  --set database.password='...' \
  --set [email protected] --set admin.password='...'

Or from the OCI registry:

helm install postal oci://ghcr.io/upstreamyard/charts/postal --set postal.webHostname=postal.example.com ...

The web interface answers on postal.webHostname only (route it with ingress.enabled=true or your own proxy). Without admin.*, create the first admin user with kubectl exec -it deploy/postal-web -- postal make-user.

After the install:

  1. Publish the DNS records (see DNS records).
  2. Make the SMTP server reachable from the internet and give Postal a fixed outgoing IP (see Receiving and sending mail from Kubernetes).
  3. In the web interface, create an organization, a mail server and an SMTP credential, and set systemEmail.username and systemEmail.password so Postal can send password resets and invitations.

Verifying the chart

Chart packages are PGP-signed. Import the public key (fingerprint 9B416F989B7E6C65F7F3BFAE7689688B20EC7813) and install with --verify:

curl -s https://upstreamyard.github.io/helm-charts/pgp_keys.asc | gpg --dearmor > upstreamyard.gpg
helm install postal upstreamyard/postal --verify --keyring upstreamyard.gpg --set ...

The OCI copy on GHCR is signed with cosign instead (see the repository README).

Requirements

  • MariaDB 10.6 or newer (required). Postal doesn't support MySQL. Tested with MariaDB 10.6 and 11.8. Postal keeps its configuration in one database (database.name) and creates one more database per mail server (<database.messageDatabasePrefix>-server-<id>), so the user needs all privileges on both:

    CREATE USER 'postal'@'%' IDENTIFIED BY '...';
    GRANT ALL PRIVILEGES ON `postal`.* TO 'postal'@'%';
    GRANT ALL PRIVILEGES ON `postal-%`.* TO 'postal'@'%';
    

    The migration Job creates the main database if it doesn't exist. Set MariaDB's innodb_log_file_size to at least 10 times smtp.maxMessageSize (e.g. 150 MB for the default 14 MB).

  • amd64 nodes. The official image is built for linux/amd64 only. On clusters with arm64 nodes, set nodeSelector: {kubernetes.io/arch: amd64}.

This chart does not deploy a database.

Receiving and sending mail from Kubernetes

A mail server needs fixed public IP addresses that other mail servers trust. This is the part of running Postal on Kubernetes that needs planning; none of it is specific to this chart, but a single VM gets it for free.

Incoming mail. Other mail servers connect to port 25 of the IP your MX records point to.

  • Expose the SMTP server with smtp.service.type=LoadBalancer and a fixed IP (smtp.service.loadBalancerIP or your cloud's annotation in smtp.service.annotations). Give it its own name with postal.smtpHostname (e.g. smtp.postal.example.com), unless the web interface uses the same IP; the MX records default to that name.
  • Postal must see the sender's real IP for spam checks and logs. Either set smtp.service.externalTrafficPolicy=Local, or let the load balancer send the PROXY protocol header and set smtp.proxyProtocol=true. Postal only reads PROXY protocol v1 (the text format); load balancers that only send v2 (e.g. AWS NLB) don't work with it.
  • Your apps can send through the same Service, on port 25 or an extra port such as 587 (smtp.service.ports).

Outgoing mail. Workers connect to port 25 of the recipients' mail servers.

  • Pods send from the IP of their node or NAT gateway. Route the workers' traffic through one fixed outgoing IP (a NAT gateway, an egress gateway, or dedicated nodes with nodeSelector), set its reverse DNS (PTR) to dns.heloHostname (defaults to postal.smtpHostname), and list it in your SPF record. Without this, Gmail and others put your mail in spam or reject it.
  • Many clouds (AWS, Google Cloud, Azure and others) block outgoing port 25 by default. Ask your provider to lift it, or send through a relay with postal.smtpRelays.
  • Postal's IP pools (sending from several IPs) need host networking and aren't supported by this chart.

The load balancer and outgoing-IP setups depend on your cloud and were not tested by us. Postal reading the client IP from a PROXY v1 header was tested in kind.

DNS records

With postal.webHostname=postal.example.com, postal.smtpHostname=smtp.postal.example.com and the default dns.* values, publish:

NameTypeValue
postal.example.comA / AAAAyour Ingress IP (web interface and API)
smtp.postal.example.comA / AAAAthe SMTP load balancer IP (also the MX host)
spf.postal.example.comTXTv=spf1 ip4:<outgoing IP> ~all
rp.postal.example.comMX10 smtp.postal.example.com
rp.postal.example.comTXTv=spf1 a mx include:spf.postal.example.com ~all
postal._domainkey.rp.postal.example.comTXToutput of kubectl exec deploy/postal-web -- postal default-dkim-record
routes.postal.example.comMX10 smtp.postal.example.com
track.postal.example.comA / AAAAyour Ingress IP (only for click and open tracking)

If the web interface and the SMTP server share one IP, leave postal.smtpHostname empty and use postal.example.com wherever smtp.postal.example.com appears.

Postal shows each sending domain's own records in the web interface and checks them.

What the chart does

  • Three Deployments from the same image: web (web interface, HTTP API, tracking; port 5000), smtp (SMTP server; port 2525 in the container, 25 on the Service) and worker (delivery, incoming processing, webhooks, housekeeping). All three scale freely: Postal coordinates through the database, and the workers elect one of themselves for housekeeping. Tested with 2 replicas each, including a login on one web pod used on the other.
  • Configuration by environment variables, so no postal.yml is needed. The DNS names default to subdomains of postal.webHostname.
  • Migrations: a Job runs postal initialize before every install and upgrade (Helm hook). It creates the database if needed, loads the schema on a fresh database or migrates it, migrates every mail server's database, and creates the admin user from admin.* if it doesn't exist. New pods wait for pending migrations instead of failing.
  • Graceful shutdown: the image's postal <command> wrapper is a bash script that runs Ruby as a child, so SIGTERM never reaches Postal and every pod is killed after its grace period; a killed worker leaves the message it was delivering locked for a day. The chart starts the processes directly, so Postal receives SIGTERM: workers finish their message, the SMTP server stops accepting connections and finishes open sessions, and a 10 s preStop sleep keeps a stopping web pod serving until it has left the Service. Tested: SMTP and worker pods stop within 1 s and log Postal's shutdown, web pods within 12 s (10 s of it the preStop sleep), instead of being killed after the grace period.
  • Probes: the web server is probed on /.well-known/jwks.json with the Host header set to postal.webHostname (it rejects other hosts); the SMTP server and workers on their health servers (/health on ports 9091 and 9090).
  • Metrics: the SMTP servers and workers serve Prometheus metrics on /metrics (port health); metrics.podMonitor.enabled=true creates a PodMonitor.
  • Security: runs as non-root (the image's postal user, UID 999), read-only root filesystem, no ServiceAccount token, and meets the Kubernetes restricted Pod Security Standard (tested). The image's Ruby carries the cap_net_bind_service file capability, and Linux refuses to start a program whose file capabilities are missing from the bounding set, so the chart drops all capabilities except NET_BIND_SERVICE. With allowPrivilegeEscalation: false the processes don't get it; they run without any capabilities (tested). Secrets come from a Secret created by the chart or from your own (existingSecret for every credential).
  • STARTTLS with a kubernetes.io/tls Secret, e.g. from cert-manager (smtp.tls.*).
  • helm test loads the login page and the signing key's public JWKS through the web Service, and checks that the SMTP Service greets and answers EHLO.

Tested end to end in kind: an app sent a message through the SMTP Service with an SMTP credential, a worker DKIM-signed it and delivered it through a relay; incoming mail to a route was accepted and processed; Postal's own emails went through systemEmail; and an upgrade from Postal 3.3.6 to 3.3.7 ran the migration Job and rolled all pods.

Configuration

Every Postal setting is an environment variable; set the ones the chart doesn't cover with extraEnv (plain values) or extraEnvFrom (Secrets), e.g. spam and virus checks (RSPAMD_*, SPAMD_*, CLAMAV_*), single sign-on (OIDC_*), Sentry (LOGGING_SENTRY_DSN) or delivery limits. See Postal's list of environment variables. A postal.yml mounted at /config/postal.yml (extraVolumes, extraVolumeMounts) is read too, but the chart's environment variables take precedence.

  • Relay hostnames must be fully qualified. Postal resolves them with its own DNS client, which ignores the cluster's search domains: smtp://relay.mail.svc.cluster.local:25 works, smtp://relay.mail.svc:25 fails with "No SMTP servers were available".
  • Click and open tracking: Postal serves tracking requests from the web server when the proxy adds the header X-Postal-Track-Host: 1 for tracking hosts. The chart's Ingress doesn't add it; route your tracking hosts through a proxy that does. Not tested by us.
  • Client IPs in the web interface: set postal.trustedProxies to your Ingress controller's pod network so Postal takes the client IP from X-Forwarded-For.
  • Your own migrations: with migrations.enabled=false, run kubectl exec deploy/postal-web -- postal upgrade after an upgrade; new pods wait until the migrations are applied (and restart if that takes longer than their probes allow). Keep the Job on for the first install: on an empty database the pods crash until the schema exists.

Production example

# values-prod.yaml
postal:
  webHostname: postal.example.com
  smtpHostname: smtp.postal.example.com
  existingSecret: postal-keys          # keys: secret-key, signing-key
  trustedProxies: ["10.0.0.0/8"]
database:
  host: mariadb.databases.svc
  existingSecret: postal-db            # key: password
systemEmail:
  username: postal/system              # an SMTP credential created in the web interface
  existingSecret: postal-smtp          # key: smtp-password
web:
  replicaCount: 2
smtp:
  replicaCount: 2
  tls:
    enabled: true
    secretName: postal-smtp-tls        # e.g. a cert-manager Certificate for postal.example.com
  service:
    type: LoadBalancer
    externalTrafficPolicy: Local
    ports:
      - name: smtp
        port: 25
      - name: submission
        port: 587
worker:
  replicaCount: 2
nodeSelector:
  kubernetes.io/arch: amd64
ingress:
  enabled: true
  className: nginx
  tls:
    - hosts: [postal.example.com]
      secretName: postal-web-tls
metrics:
  podMonitor:
    enabled: true

Known issues

  • The official image is amd64 only. Pods scheduled on arm64 nodes fail with exec format error.
  • Postal's own postal <command> wrapper doesn't pass on SIGTERM (see What the chart does). The chart works around it; if you override the container args, keep Ruby as the main process.

Values

KeyTypeDefaultDescription
admin.emailstring""Email of the first admin user. Leave empty to create it yourself with postal make-user (see the README).
admin.existingSecretstring""Name of an existing Secret that holds the admin password.
admin.existingSecretKeystring"admin-password"Key in existingSecret that holds the admin password.
admin.firstNamestring"Postal"First name of the admin user.
admin.lastNamestring"Admin"Last name of the admin user.
admin.passwordstring""Password of the admin user. Stored in a Secret created by this chart. Ignored when existingSecret

Deploy postal with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has postal on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpostal is pinned at v0.1.6 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply