How to send email from the Linux command line (CentOS, Redhat, Ubuntu and Debian)

Install mail Command:

Let’s use one of below command to install mail command as per your operating system. For RHEL based systems, this command installed from mailx rpm packages and on Debian based system this command found in mailutils package.

Install mail command on CentOS/Redhat 7/6/5:

yum install mailx

Install mail command on Fedora 22+:

dnf install mailx

Install mail command on Ubuntu/Debian/LinuxMint:

sudo apt-get install mailutils

Sending Test Email

After installing mail command packages in your system, send a test email using below command.

echo "Message Body" | mail -s "Message Subject"