Guide to send an email from CLI using SMTP in Linux
Electronic mail is a method of exchanging messages between people using electronic devices. There are several methods to send an email, in this guide we are going to focus on sending an email from Linux CLI using SMTP.
Requirements send an email from CLI using SMTP :
- Linux with sudo permissions
- SMTP details for your email
Procedure :
- Installing epel-release on your system by using the following command.
yum install epel-release - Installing SMTP on your system by using the following command.
sudo yum install ssmtp - Open the following file in an editor.
sudo vi /etc/ssmtp/ssmtp.conf - Add the following lines to the file:
TLS_CA_FILE=/etc/pki/tls/certs/ca-bundle.crt
mailhub=smtp.gmail.com:587
useSTARTTLS=YES
AuthUser=youremail@mail.com
AuthPass=your_password

Save the file by pressing the Esc key, type `:wq` to write the file and exit the editor.
Note :mailhubcould be already defined in the ssmtp.conf file and make sure you edit the definition instead of adding a newmailhubdefinition. - Send the email using the following command.
echo -e "To: receiver@mail.com\nFrom: Sender Name <sender@mail.com>\nSubject: Email from CLI\n\nTest Email sent using SMTP from CLI" | ssmtp -v receiver@mail.com
Congratulations now you know how to send email from Linux using SMTP.
Read more helpful guides like this on our blog. Click here

