How to send email with mailx and external Google SMTP server from CentOS Linux
Mailx or mail (mail is just a symlink to mailx) is standard email client for email sending from server with alert message. In this tutorial we will send email with mailx and using Google/GoogleApps SMTP server for email sending from CentOS (I guess it’s the same on all Linux distros). Compared to mutt you don’t need to do anything manually/compiled from source here for use with external SMTP server.
# In you already dont have mailx - install it yum install mailx -y # Creating folder for certificates and downloading Google cert inside mkdir ~/.certs certutil -N -d ~/.certs echo -n | openssl s_client -connect smtp.gmail.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/gmail.crt certutil -A -n "Google Internet Authority" -t "C,," -d ~/.certs -i ~/.certs/gmail.crt # Sending od test email echo -e "Sadrzaj emaila" | mailx -v -s "Email subject" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://smtp.gmail.com:587 -S from="tvoj-email@gmail.com(Ime Prezime)" -S smtp-auth-user=tvoj-email@gmail.com -S smtp-auth-password=lozinka-za-gmail -S ssl-verify=ignore -S nss-config-dir=~/.certs tvoj-drugi-neki-nalog@gdegod.com # Creating a alias for easier email sending vi ~/.bash_profile # Put this two lines on bottom of .bash_profile alias mailx='mailx -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://smtp.gmail.com:587 -S from="tvoj-email@gmail.com(Ime Prezime)" -S smtp-auth-user=tvoj-email@gmail.com -S smtp-auth-password=lozinka-za-gmail -S ssl-verify=ignore -S nss-config-dir=~/.certs' alias mail=mailx # Make alias permanent . ~/.bash_profile # Testing of email send with simplified command echo "Tekst poruke" | mail -s "Test email" tvoj-drugi-neki-nalog@gdegod.com