How to use MSMTP as email software in Zoneminder (v1.33.14.) on Ubuntu 19.04

The  software MSMTP is a latest  SMTP client runs on a wide variety of platforms. It seems msmtp is overtaking ssmtp which is a software of similar nature.

At present the Zoneminder has been  programmed  to use ssmtp as an email software under NEW_MAIL_MODULES.

To send email alerts in zmfilter.pl , a programme has been written to use MIME::Lite module  which uses “sendmail” command.

The worked example in this blog post shows how to use MSMTP  insted of SSMPT  in Zoneminder to send email alerts of motion detection events.

 

First you will have to install MSMTP  ( If  ssmtp , sendmail  available , please uninstall completely )

Open the Ubuntu terminal and run

sudo apt install msmtp

After installing , you can find the main executable file msmtp at /usr/binScreenshot from 2019-10-21 11-17-51

Figure:- 1 msmtp file created at /usr/bin/

Then create   sendmail file which a symlink of  msmtp ( at /usr/bin)  in /usr/sbin/ .

Run on the Ubuntu terminal

sudo ln -s /usr/bin/msmtp /usr/sbin/sendmail

Note: before making above symlink , make sure that there is no sendmail file in /usr/bin

When zmfilter.pl searchs  for /usr/sbin/sendmail , it redirect to msmtp which is the main executable file at /usr/bin/.

Screenshot from 2019-10-20 22-51-42

Figure:-2 sendmail file at /usr/sbin

Now you will have to create a configuration file called msmtprc which contains email hosts ,ports ,certificates ,email details etc at the directory /etc/

Creating a ~/.msmtprc file in home directory is not essential as we are making a file at /etc/ . Then msmtp   by default , connects with    msmtprc at /etc/

On the Ubuntu terminal

sudo gedit /etc/msmtprc

Screenshot from 2019-10-21 11-13-49

Figure:- 3 msmtprc at /etc/

When the empty file is opened, enter the following scripts

# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log

# Gmail
account gmail
host smtp.gmail.com
port 587
from your gmail address
user your gmail address
password your gmail password

# Set a default account
account default : gmail

 

Screenshot from 2019-10-21 22-16-22

Figure:-4 Scrips in /etc/msmtprc

To add group www-data to the file

Then on the Ubuntu terminal

sudo chown root:www-data /etc/msmtprc

Now you can try a test mail on the terminal

 

echo "Subject: sendmail test" | sendmail -v bkjaya1952@aol.com

 

Note : replace bkjaya1952@aol.com with your receiving email

How to make changes in Zoneminder for MSMTP

It is assumed that the Zoneminder software is already installed in your Ubuntu PC

Please refer the following link for installation guide for Zoneminder

HOW TO INSTALL ZONEMINDER, v1.33.0. ON UBUNTU 18.10 /19.04

Screenshot from 2019-10-21 11-07-57

Figure:- 5 ZM-console

Go to Options/Email on the ZM-Console

And  tick boxes and make changes in the cages as sown in following two figures

 

Screenshot from 2019-10-21 22-43-28

Figure:- 6 Upper part of the page at Options/Email

Please note the following additional entries under EMAIL_BODY cage

Attach (first) event image with the highest score : %EIM%

Attach event mpeg video : %EV%

 

Screenshot from 2019-10-21 11-10-46

Figure:-7 Lower part of the page at Options/Email

Making a filter to initiate email process

Make a filter as shown in the figure below and execute

Screenshot from 2019-10-21 09-47-52

Figure:-8 filter to select events of maximum score is > or= to 5 and send email alerts

Screenshot from 2019-10-21 11-26-15

Figure:- 9 Zm-System Log showing email sending process

Following 2 figures show the received emails

Screenshot from 2019-10-21 11-11-31

Figure:- 10 received email alerts

Screenshot from 2019-10-21 12-44-34

 

Figure:- 11 received email alerts

 

 

 

 

 

 

NOTE:- Please refer the following link to find the latest developments :

How to resolve e- mailing problem in Zoneminder when using msmtp with gmail