msmtp

msmtp is an SMTP client that can be used to send mails from mail user agents(MUA). It forwards mails to an SMTP server (for example at a free mail provider), which takes care of the final delivery.

It can be used to send emails with gmail account but requires changing some security related settings in gmail account.

msmtp was being used in Openwrt for sending daily emails through gmail to Zerodha for the past many years, which was configured as per this article1.

When the config file /etc/msmtprc was copied over, it worked perfectly in Alpine Linux .

After installing msmtp and mailx packages, the following needs to be done in Alpine Linux..

  1. Add the email address as alias for root account.
    $ cat /etc/aliases
    root: kXXXX@gmail.com
    
  2. Create a softlink for sendmail to msmtp, so it appears as follows:
    $ ls -l /usr/sbin/sendmail
    lrwxrwxrwx    1 root     root            14 Oct 10 14:15 /usr/sbin/sendmail -> /usr/bin/msmtp*
    
  3. Ensure that the config file for mstmtp /etc/msmtprc is owned by root and has permissions set to 600 and appears as follows:
    $ ls -l /etc/msmtprc
     -rw-------    1 root     root          1580 Oct 10 14:11 /etc/msmtprc
    $ doas cat /etc/msmtprc |grep -v '^ *#'|grep "\S"
    account default
    host smtp.gmail.com
    port 587
    auto_from off
    from kXXX@gmail.com
    aliases /etc/aliases
    tls on
    tls_starttls on
    tls_trust_file /etc/ssl/certs/ca-certificates.crt
    syslog LOG_MAIL
    auth on
    user kXXXX@gmail.com
    password XXXX
    
  4. Configure google app password ↗ , if you are not using OAuth.
  5. Test the configuration using the below command.
    $ echo -e "Subject: Hello!\n\nHello, world!" |doas sendmail root
    

© Prabu Anand K 2020-2026