Sending emails with bash script - lmkelly/Autoguard GitHub Wiki
Resource
Resource2
- First enable less secure apps on the gmail account to be used (if using gmail)
sudo apt-get install msmtp-mta
nano ~/.msmtprc
Add the following lines to the file
defaults
#change the location of the log file to any desired location.
logfile ~/msmtp.log
account gmail
auth on
host smtp.gmail.com
from <[email protected]>
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
user <[email protected]>
password <your-password>
port 587
#set gmail as your default mail server.
account default : gmail
Lock it down
chmod 600 .msmtprc
Install heirloom-mailx source
nano /etc/apt/sources.list
Add the following
deb http://security.ubuntu.com/ubuntu trusty-security main universe
Install heirloom-mailx
sudo apt-get update
sudo apt-get install heirloom-mailx
Create config file for mailx
nano ~/.mailrc
Add the following lines
set sendmail="/usr/bin/msmtp"
set message-sendmail-extra-arguments="-a gmail"
Example command to send mail
mail -s 'message subject' [email protected] <<< 'testing message body'