1. Install packages
apt install msmtp msmtp-mta
2. Create configuration file
cat <<EOF > /etc/msmtprc
# Set default values for all following accounts.
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile ~/.msmtp.log
#Profiles
account mail-server-1
tls_starttls off
host smtp.example.com
port 465
from sender-account@example.com
user sender-account@example.com
password HIDDENPASSWORD!!
account mail-server-2
host mail.example2.net
port 587
from test@example2.net
user test@example2.net
password HIDDENPASSWORD!!
# Set a default account
account default : mail-server-1
EOF
Example:
echo "This is a test email." | msmtp ross@gmail.com