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 it can help to send e-mail using a command or code script.

Requirements

OpenWrt's minimum size requirement = (2.5 MB)

Installation and Configuration

Step 1: Install Msmtp
  1. Select Tabs System - Software
  2. Click 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 you can add it by do "touch msmtprc" command
You need to edit it or add it
  • account default
  • host mailhub.oursite.example ---> host smtp.gmail.com
  • port 587 *add it
  • #tls on *unhash --> tls on
  • #tls_trust_file /etc/ssl/certs/ca-certificates.crt *replace it with ---> tls_certcheck off
  • *and add under / below syslog LOG_MAIL*

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 [email protected]
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 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