Installs and configures msmtp, a lightweight SMTP client, on Debian-based Linux systems. msmtp is a sendmail-compatible SMTP client that can be used to relay mail through an external SMTP server.
The msmtp-mta package provides a /usr/sbin/sendmail symlink, so services like fail2ban and cron continue to work without changes.
If you're using PHP and would like to route all PHP email through msmtp, you will need to update the sendmail_path configuration option in php.ini, like so:
sendmail_path = "/usr/bin/msmtp -t"Roots is an independent open source org, supported only by developers like you. Your sponsorship funds WP Packages and the entire Roots ecosystem, and keeps them independent. Support us by purchasing Radicle or sponsoring us on GitHub — sponsors get access to our private Discord.
A Debian-based (eg: Ubuntu) system.
This role is designed for Trellis and defaults to using Trellis's mail_* variables. When used outside of Trellis, override the variables below.
Available variables are listed below, along with default values (see defaults/main.yml):
msmtp_server: "{{ mail_smtp_server }}"
msmtp_from: "{{ mail_admin }}"
msmtp_domain: "{{ mail_hostname }}"
msmtp_user: "{{ mail_user }}"
msmtp_password: "{{ mail_password }}"The SMTP server (host:port format, supports IPv6 with brackets like [::1]:587), envelope sender, EHLO domain, and credentials. If no port is specified in msmtp_server, the msmtp_port default (587) is used.
For non-Trellis usage, set these directly:
msmtp_server: smtp.example.com:587
msmtp_from: admin@example.com
msmtp_domain: example.com
msmtp_user: smtp_user
msmtp_password: secretmsmtp_auth: "on"SMTP authentication. Set to "off" to disable.
msmtp_tls: "on"
msmtp_tls_starttls: "on"TLS settings.
msmtp_allow_from_override: "on"Allow the envelope-from passed on the command line (e.g. via msmtp -f) to override msmtp_from. Required for WordPress multisite so per-site From addresses aren't rewritten. Set to "off" to force all mail through msmtp_from.
msmtp_accounts: []Optional list of additional accounts. Each account supports: name, host, port, from, user, password, auth, tls, tls_starttls, and domain. See defaults/main.yml for an example.
With Trellis (uses mail_* variables automatically):
- hosts: servers
roles:
- { role: roots.msmtp }Standalone:
- hosts: servers
roles:
- role: roots.msmtp
vars:
msmtp_server: smtp.example.com:587
msmtp_from: admin@example.com
msmtp_domain: example.com
msmtp_user: smtp_user
msmtp_password: "{{ vault_smtp_password }}"Keep track of development and community news.
- Join us on Discord by sponsoring us on GitHub
- Join us on Roots Discourse
- Follow @rootswp on Twitter
- Follow the Roots Blog
- Subscribe to the Roots Newsletter