What is msmtp
msmtp is an SMTP client that allows you to transmit an email to an SMTP server which takes care of further delivery. If you do not host your own mail server (and instead you use a third-party provider such as G Suite to host your mail), then you do not need a full-fledged mail server (MTA) such as Postfix, Exim, etc. Instead, you can just use this lightweight SMTP client to transmit your mail to Google's SMTP server.
# yum groupinstall "Development Tools"
# yum install texinfo
# yum install gnutls gnutls-devel
# yum install ca-certificates
# git clone https://git.marlam.de/git/msmtp.git
# cd msmtp
# autoreconf -i
# make install
# vim ~/.msmtprc
# Set default values for all following accounts. defaults auth on tls on tls_starttls on tls_trust_file /etc/ssl/certs/ca-bundle.crt logfile ~/.msmtp.log # Gmail account gmail host smtp-relay.gmail.com # host for G Suite users, change it if you use Gmail without G suite port 587 from email@example.com user firstname.lastname@example.org password thepassword # Gmail # account anotherprovider # host smtp.anotherprovider.net # Set a default account account default : gmail
Send email via the command line
# echo "hello world" | /usr/local/bin/msmtp email@example.com
# printf "To: firstname.lastname@example.org\nFrom: email@example.com\nSubject: Email Test Using MSMTP\n\nHello there. This is email test from MSMTP." | /usr/local/bin/msmtp firstname.lastname@example.org
Note: Google has blocked plain smtp authentication, and requires OAuth. Absurdly it worked for a day then all emails were blocked. Instead of trying to make OAuth work, G Suite allowed me to add a list of server IPs allowed to send email and would then let me disable smtp authentication altogether (switched
off). The alternative is to allow "less secured apps" in Google's settings.