Packetwatch.net

Email notifications using Msmtp in FreeNAS



Last modified: Mar. 22, 2010

Contents
1 - Summary
2 - Msmtp configuration
3 - Example shell script


1 - Summary

This guide will show how to send emails for system events using msmtp in
FreeNAS. Msmtp is an SMTP client using to send email. This has been tested in
FreeNAS 0.69.2.4700.


2 - Msmtp configuration

Log into the website interface and go to the System menu and select Advanced.
Click on the Email tab and type in the configuration information. Here is some
example information.
  Outgoing mail server: mail.test.com
  Port: 25
  Security: None
  From email: noreply@test.com
After typing in the information, click on Save.


3 - Example shell script

Here is an example shell script that sends an email.

#!/bin/sh

hostname=/bin/hostname
host=`$hostname -s`
date=/bin/date
current_day=`$date +%m/%d/%y`
current_time=`$date +%H:%M:%S`
printf=/usr/bin/printf
from="Test <noreply@test.com>"
recipient=testuser@test.com
#recipient="testuser1@test.com;testuser2@test.com"
msmtp=/usr/local/bin/msmtp
msmtp_config=/var/etc/msmtp.conf

body="This is a test."
subject="Test sent from $host [$current_day $current_time]"
$printf "From: $from\nTo: $recipient\nSubject: $subject\n\n$body" | $msmtp --file=$msmtp_config -t
exit 0


Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2017.