Installs and configures MSMTP for email forwarding on Ubuntu.
make msmtpSee defaults/main.yml.
| Variable | Purpose |
|---|---|
msmtp_domain |
Mail domain, used to build msmtp_send_all_email_to. Required |
msmtp_user |
Upstream SMTP username. Required |
msmtp_password |
Upstream SMTP password. Required, rendered into /etc/msmtprc-relay only |
msmtp_host, msmtp_port |
Upstream SMTP server |
msmtp_relay_interface |
Interface msmtpd listens on. Must be 127.0.0.1 or ::1 |
msmtp_relay_port |
Port msmtpd listens on. Must be unprivileged (1024 to 65535) |
Set the required vars per host in host_vars/. msmtp_password is not among them: it is injected under that name
rather than holding a value. The role asserts them, and the relay constraints, before its first
task, which uninstalls the host's existing MTA.
- Two config files. Local mail is submitted via
/usr/sbin/sendmail(frommsmtp-mta), which reads world-readable/etc/msmtprc. That file must stay world-readable (cron drops to the crontab owner before invoking the MTA, and Ubuntu'smsmtpis not setgid), so it holds no credentials: it points atmsmtpdon the relay interface, which relays via/etc/msmtprc-relay(mode0600), where the credentials live. - The relay is unauthenticated, so
msmtp_relay_interfacemust stay on loopback. Its port is unprivileged so the daemon needs noCAP_NET_BIND_SERVICE. - A systemd drop-in sets
User=msmtpinstead ofDynamicUser=true.msmtprefuses a-Cconfig containing secrets unless the file is owned by the calling euid with no group or other permission bits, and aDynamicUserUID can never own a file on disk. The drop-in restores the sandboxingDynamicUserimplied. - AppArmor.
msmtp's profile grants read of/etc/msmtprcbut not/etc/msmtprc-relay. It is disabled by default; the role writes the local rule regardless, so enforcing it later cannot bounce every message. - msmtpd is restarted every run, before
/etc/msmtprcis written to point clients at it. It holds no queue, so the restart is safe. - msmtp does not queue. An unreachable upstream means the message is rejected, not retried. Anything that must survive an outage needs a queuing MTA.
# Verify delivery end to end
echo test | mail -s test root
journalctl -u msmtpd -n 20