Packetwatch.net

Email notifications using Msmtp in MythDora



Last modified: Jan. 30, 2010

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


1 - Summary

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


2 - Msmtp installation

Install the msmtp package.
# sudo yum -y install msmtp
[sudo] password for user: 


3 - Msmtp configuration

Find where the msmtp application was installed to.
# rpm -ql msmtp-* | grep bin
/usr/bin/msmtp

Find where the configuration file should be put.
# strings /usr/bin/msmtp | grep msmtp.conf
# rpm -ql msmtp-* | grep msmtp.conf

You can create your own configuration file. Here is a simple example.
  account default
  host mail.test.com
  port 25
  protocol smtp
  from noreply@test.com
  syslog LOG_MAIL
# sudo touch /etc/msmtp.conf
[sudo] password for user: 
# sudo chmod 600 /etc/msmtp.conf
[sudo] password for user: 
# sudo vi /etc/msmtp.conf 
[sudo] password for user: 


4 - Example shell script

Here is an example shell script that sends an email.

#!/bin/sh

printf=/usr/bin/printf
#from=noreply@test.com
from="Test <noreply@test.com>"
recipient="testuser@test.com"
#recipient="testuser1@test.com,testuser2@test.com"
hostname=/bin/hostname
host=`$hostname -s`
subject="Test sent from $host"
date=/bin/date
current_time=`$date +%H:%M`
current_day=`$date +%m/%d/%y`
body="This is a test. It was sent at $current_time on $current_day."
msmtp=/usr/bin/msmtp
msmtp_config=/etc/msmtp.conf

$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-2024.