Send Email with Msmtp on OpenWrt

Msmtp is an SMTP client it it transmits a mail to an SMTP server (for example at a free mail provider) which takes care of further delivery.

To use this program with your mail user agent (MUA), create a configuration file with your mail account(s) and tell your MUA to call msmtp instead of /usr/sbin/sendmail. With Msmtp on OpenWrt you able to send e-mail using a command or code script.

Requirements

Minimum free space size requirement = (2.5 MB)

Installation and Configuration

Step 1: Install Msmtp
  1. Select Tabs System - Software
  2. Select Update List
  3. In download and install packages type "msmtp" then click ok
Step 2. Configure Msmtp
  1. cd /etc
  2. vi msmtprc *If there are no msmtprc files, add the files by "touch msmtprc" command
You need to edit it or add it
  • account default
  • host mailhub.oursite.example ---> host smtp.gmail.com
  • port 587 *add port
  • #tls on *remove hashtag to --> tls on
  • #tls_trust_file /etc/ssl/certs/ca-certificates.crt *replace with ---> tls_certcheck off
  • *and add under / below syslog LOG_MAIL*
    • auth login
    • user your.email@gmail.com
    • password gmailpassword
    • from your.email@gmail.com

Testing

Run this command from SSH on your router:
echo -e "Subject: Test Mail\r\n\r\nThis is a test mail" |msmtp --debug --from=default -t username@gmail.com
Then check the destination email inbox.

Additional Msmtp options parameters

  • --debug *If you want to see log of sending mail
  • --from=default *It's default account located in /etc/msmtprc
  • -t username[at]gmail.com *It will send email to the destination email

Reference

  1. Installing and Configuring mSMTP - VigasDeep
  2. Image by Cairo on Flickr used under CC BY 2.0 / Add More Shadow

Comments