Using Postfix for this solution.
Follow instructions at https://www.linode.com/docs/guides/configure-postfix-to-send-mail-using-gmail-and-google-workspace-on-debian-or-ubuntu/
Or see the same at Sending Emails Using Postfix From Your Linux Server
For CENTOS8:
dnf install postfix ca-certificates mutt dnf install cyrus-sasl, cyrus-sasl-gssapi, cyrus-sasl-lib, cyrus-sasl-plain systemctl start postfix systemctl enable postfix
Next perform the following steps as root:
cd /etc/postfix cp main.cf main.cf.distro mkdir /etc/postfix/sasl cd /etc/postfix/sasl vi sasl_passwd
Add this line:
[smtp.gmail.com]:587 [email protected]:password
postmap /etc/postfix/sasl/sasl_passwd chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db chmod 0600 /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db
vi /etc/postfix/main.cf
Comment out this line:
#smtp_tls_security_level = may
Now wdd to the end of the main.cf file:
# Local Edits relayhost = [smtp.gmail.com]:587 # Enable SASL authentication smtp_sasl_auth_enable = yes # Disallow methods that allow anonymous authentication smtp_sasl_security_options = noanonymous # Location of sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd # Enable STARTTLS encryption smtp_tls_security_level = encrypt # Location of CA certificates smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
Restart postfix:
systemctl restart postfix
Send test message:
mutt -s "Test" [email protected] </dev/null