Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 2.46 KB

File metadata and controls

55 lines (44 loc) · 2.46 KB

ansible-role-msmtp

Installs and configures MSMTP for email forwarding on Ubuntu.

Usage

make msmtp

Variables

See 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.

Notes

  • Two config files. Local mail is submitted via /usr/sbin/sendmail (from msmtp-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's msmtp is not setgid), so it holds no credentials: it points at msmtpd on the relay interface, which relays via /etc/msmtprc-relay (mode 0600), where the credentials live.
  • The relay is unauthenticated, so msmtp_relay_interface must stay on loopback. Its port is unprivileged so the daemon needs no CAP_NET_BIND_SERVICE.
  • A systemd drop-in sets User=msmtp instead of DynamicUser=true. msmtp refuses a -C config containing secrets unless the file is owned by the calling euid with no group or other permission bits, and a DynamicUser UID can never own a file on disk. The drop-in restores the sandboxing DynamicUser implied.
  • AppArmor. msmtp's profile grants read of /etc/msmtprc but 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/msmtprc is 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.

Operations

# Verify delivery end to end
echo test | mail -s test root
journalctl -u msmtpd -n 20