Using mSmtp on Linux Centos

 Install

yum install msmtp
yum install ca-certificates

Create config file

Create /etc/msmtprc

#set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file    /etc/pki/tls/certs/ca-bundle.crt
logfile        ~/.msmtp.log
# Gmail
account        gmail
host           smtp.xxx.com
port           587
from           xxx@yyy.com
user           xxx@yyy.com
password       zzz

# Gmail
account        anotherprovider
host           smtp.anotherprovider.net
port           587
from           @anotherprovider.net
user           @anotherprovider.net
password

# Set a default account
account default : gmail

Sending mail

 Simple

echo "Hello this is sending email using msmtp" | msmtp recipent@domain.com

From a file

Create a file email.txt

To: xxx@yyy.com
From: aaa@bbb.com
Subject: Email Test using MSMTP from File
Hi,
This is an email test from file.

From Mutt

yum install mutt

Edit /root/.muttrc

set sendmail="/usr/bin/msmtp"
set from="Fred Bloggs <xxx@yyy.com>"

Sending Logwatch Report from Mutt

  • create report if you don't have one

    logwatch --detail High --filename report.txt
    
    echo "Logwatch Report attached." | mutt -d 1 -s "Subject" person@receiving.com -a ./report.txt