Mail Relay Deploy¶
mail_relay_deploy¶
Deploy Postfix as an edge mail relay server.
Overview¶
This role configures a thin Postfix relay on an edge server that:
Receives inbound mail on port 25 for configured domains
Applies greylisting via postgrey to reduce spam
Relays accepted mail to the backend server
Accepts authenticated outbound mail from backend on port 587
Architecture¶
INTERNET EDGE (this role) BACKEND
mail.wersdoerfer.de macmini
[External MTA] ──► Port 25 ──► [Postfix Relay] ──────► Port 25 ──► [Backend Postfix]
- Greylisting
- TLS termination
- No recipient validation
[Backend] ◄── Port 587 ◄── [SMTP AUTH] ◄───────────────────── [Submission]
- TLS required
- SASL authentication
Requirements¶
Debian/Ubuntu target system
Let’s Encrypt certificate for relay hostname
Network connectivity to backend server
Required Variables¶
# Domains to accept mail for
# For IDNs, include the A-label (punycode).
# U-label entries are optional forward-compatibility for future SMTPUTF8 enablement.
mail_relay_domains:
- "xn--wersdrfer-47a.de"
- "wersdörfer.de"
# Backend server to relay inbound mail to
mail_relay_backend_host: "smtp.home.xn--wersdrfer-47a.de"
# SASL password for backend authentication on submission
mail_relay_sasl_password: "CHANGEME" # Set via SOPS
Optional Variables¶
Server Configuration¶
Variable |
Default |
Description |
|---|---|---|
|
|
Hostname (must match PTR) |
|
|
Mail domain |
|
|
Backend relay port |
|
|
Advertise SMTPUTF8 support ( |
TLS¶
Variable |
Default |
Description |
|---|---|---|
|
|
Enable TLS |
|
Let’s Encrypt path |
Certificate path |
|
Let’s Encrypt path |
Private key path |
|
|
Inbound TLS level |
Greylisting¶
Variable |
Default |
Description |
|---|---|---|
|
|
Enable postgrey |
|
|
Delay in seconds |
Rate Limiting¶
Variable |
Default |
Description |
|---|---|---|
|
|
Connections per minute |
|
|
Recipients per minute |
Recipient Rewrites¶
Variable |
Default |
Description |
|---|---|---|
|
|
Optional recipient envelope rewrites ( |
When enabled, rewrites are applied to envelope recipients only (recipient_canonical_classes = envelope_recipient).
Supported rewrite keys/values are user@domain and domain-wide @domain patterns.
Example Playbook¶
---
- name: Deploy Mail Relay
hosts: edge
become: true
vars:
mail_secrets: "{{ lookup('community.sops.sops', 'secrets/prod/mail.yml') | from_yaml }}"
roles:
- role: local.ops_library.mail_relay_deploy
vars:
mail_relay_domains:
- "xn--wersdrfer-47a.de"
- "wersdörfer.de"
mail_relay_recipient_rewrites:
- from: "@wersdörfer.de"
to: "@xn--wersdrfer-47a.de"
mail_relay_backend_host: "smtp.home.xn--wersdrfer-47a.de"
mail_relay_sasl_password: "{{ mail_secrets.relay_sasl_password }}"
Files Created¶
Path |
Description |
|---|---|
|
Main Postfix configuration |
|
Postfix service definitions |
|
Domain → backend routing |
|
Accepted domains |
|
Optional recipient rewrite map |
|
SASL credentials |
|
SASL configuration |
|
Greylisting settings |
|
Greylisting whitelist |
Services Managed¶
postfix- Mail transfer agentpostgrey- Greylisting policy server
Ports¶
Port |
Protocol |
Direction |
Description |
|---|---|---|---|
25 |
SMTP |
Inbound |
Receive mail from internet |
587 |
Submission |
Inbound |
Accept authenticated mail from backend |
465 |
SMTPS |
Inbound |
Implicit TLS submission (alternative) |
Security Notes¶
No recipient validation - Edge has no database access. Unknown recipients are rejected by backend after relay. Acceptable backscatter risk for personal mail.
Greylisting - Temporarily rejects unknown senders. Reduces spam significantly.
SASL authentication - Required for submission (port 587). Backend must authenticate to send outbound mail.
TLS - Opportunistic for port 25 (internet), mandatory for submission.
DNS Requirements¶
; MX record pointing to edge
@ MX 10 mail.wersdoerfer.de.
; A/AAAA for edge server
mail.wersdoerfer.de. A 213.239.212.206
mail.wersdoerfer.de. AAAA 2a01:4f8:a0:82dc::2
; PTR record (set at hosting provider)
; 213.239.212.206 → mail.wersdoerfer.de
Troubleshooting¶
Check Postfix status¶
systemctl status postfix
postfix check
View mail queue¶
mailq
postqueue -p
Check logs¶
tail -f /var/log/mail.log
journalctl -u postfix -f
Test SMTP¶
# Test port 25
telnet mail.wersdoerfer.de 25
# Test with openssl
openssl s_client -connect mail.wersdoerfer.de:587 -starttls smtp
Check greylisting¶
systemctl status postgrey
grep postgrey /var/log/mail.log
License¶
MIT