Skip to content

roots/ansible-role-msmtp

Ansible Role: msmtp

Release Build Status Galaxy Downloads Follow Roots Sponsor Roots

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"

Support us

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.

Requirements

A Debian-based (eg: Ubuntu) system.

Role Variables

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: secret
msmtp_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.

Example Playbook

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 }}"

Community

Keep track of development and community news.

About

Ansible Role: msmtp — a lightweight SMTP client and sendmail replacement for Debian-based systems

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages