Cyberithub

How to Install mail command in RHEL / CentOS 7/8 Using 5 Best Steps

In this article I will take you through the Steps to install mail command in RHEL / CentOS 7/8 Using 5 Easy Steps. mail command is a very useful command in Linux to send a mail through terminal. It is very frequently used in Bash Shell Scripting to send a mail once a specific task is performed. Mostly you will see its wide usage in Linux Backup Servers where the Backup Script will send a mail before starting the backup and after completion of the backup. Hence it is very important to have this tool in your Linux System. Now Let’s go through the detailed steps to install mail command in Linux.

How to Install mail command in RHEL / CentOS 7/8 Using 5 Best Steps 1

How to Install mail command in RHEL/CentOS 7/8

Also Read: 18 Popular mount/umount command examples in Linux

Step 1: Prerequisites

a)You need to have running RHEL/CentOS 7/8 based Systems.

b)You should have yum tool installed in your System. Please Check Top 22 YUM Command Examples in RedHat/CentOS 7 to know more about yum utility.

c)You should have root or sudo access to run Privileged Commands. Please Check How to Add User to Sudoers to know more about providing sudo access to the User.

Step 2: Update Your System

First you need to update your system using yum update -y command before installing any new packages to make sure that all the installed packages are updated with the latest version. This will ensure all the dependent packages required by mailx package are fully updated. Otherwise installation of new package might complain about not having a specific version of dependent packages.

If you don’t have Internet Connection in your System to run the update then you can setup local YUM repository and update from there. Please check How to Setup Local YUM Repository on CentOS 7 Using 8 Easy Steps to know more about the setup.

[root@localhost ~]# yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-57.el7 will be updated
---> Package curl.x86_64 0:7.29.0-57.el7_8.1 will be an update
---> Package dbus.x86_64 1:1.10.24-13.el7_6 will be updated
---> Package dbus.x86_64 1:1.10.24-14.el7_8 will be an update
---> Package dbus-libs.x86_64 1:1.10.24-13.el7_6 will be updated
---> Package dbus-libs.x86_64 1:1.10.24-14.el7_8 will be an update
---> Package grub2.x86_64 1:2.02-0.81.el7.centos will be updated
---> Package grub2.x86_64 1:2.02-0.86.el7.centos will be an update
---> Package grub2-common.noarch 1:2.02-0.81.el7.centos will be updated
---> Package grub2-common.noarch 1:2.02-0.86.el7.centos will be an update
---> Package grub2-pc.x86_64 1:2.02-0.81.el7.centos will be updated
---> Package grub2-pc.x86_64 1:2.02-0.86.el7.centos will be an update
---> Package grub2-pc-modules.noarch 1:2.02-0.81.el7.centos will be updated
---> Package grub2-pc-modules.noarch 1:2.02-0.86.el7.centos will be an update
---> Package grub2-tools.x86_64 1:2.02-0.81.el7.centos will be updated
---> Package grub2-tools.x86_64 1:2.02-0.86.el7.centos will be an update
---> Package grub2-tools-extra.x86_64 1:2.02-0.81.el7.centos will be updated
---> Package grub2-tools-extra.x86_64 1:2.02-0.86.el7.centos will be an update
---> Package grub2-tools-minimal.x86_64 1:2.02-0.81.el7.centos will be updated
---> Package grub2-tools-minimal.x86_64 1:2.02-0.86.el7.centos will be an update
---> Package ipset.x86_64 0:6.29-1.el7 will be updated
---> Package ipset.x86_64 0:7.1-1.el7 will be an update
---> Package ipset-libs.x86_64 0:6.29-1.el7 will be updated
---> Package ipset-libs.x86_64 0:7.1-1.el7 will be an update
---> Package ipset-service.noarch 0:6.29-1.el7 will be updated
---> Package ipset-service.noarch 0:7.1-1.el7 will be an update
---> Package iptables.x86_64 0:1.4.21-24.1.el7_5 will be updated
---> Package iptables.x86_64 0:1.4.21-34.el7 will be an update
---> Package iptables-services.x86_64 0:1.4.21-24.1.el7_5 will be updated
---> Package iptables-services.x86_64 0:1.4.21-34.el7 will be an update

Step 3: Install mail command in Linux

Once System is successfully updated you can install mailx package from repository using yum install mailx -y command as shown below. This command will download and install the latest version of mailx package from enabled Repository.

[root@localhost ~]# yum install mailx -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: d36uatko69830t.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
mailx x86_64 12.5-19.el7 base 245 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 245 k
Installed size: 466 k
Downloading packages:
mailx-12.5-19.el7.x86_64.rpm | 245 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mailx-12.5-19.el7.x86_64 1/1
Verifying : mailx-12.5-19.el7.x86_64 1/1

Installed:
mailx.x86_64 0:12.5-19.el7

Complete!

Step 4: Check mail command version

After installing mailx package you can verify the mail command version using mail -V command as shown below. As shown in the below output, current version is 12.5.

[root@localhost ~]# mail -V
12.5 7/5/10

Step 5: Send a Test email using mail command in Linux

Now it is the time to test the functionality of mail command from CLI by sending a test email to localhost using below command. Here we are sending "This is test email" body with the subject "Test email" to email ID root@localhost.

[root@localhost ~]# echo "This is test email" | mail -s "Test Email" root@localhost

-s : Specify subject on command line. Check mail command Man Page to know more about this.

Once the mail is sent you can verify it from /var/spool/mail/root log file as shown below. If you grab the last few lines using tail command then you can see the Test email sent from email ID root@localhost.localdomain.

[root@localhost ~]# tail -f /var/spool/mail/root
Subject: Test Email
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20200807153908.69F3B4DC916@localhost.localdomain>
From: root@localhost.localdomain (root)

This is test email

 

 

Popular Recommendations:-

10 Popular nfsstat command examples in Linux for Professionals (cheatsheet)

10 Useful nfsstat and nfsiostat examples to troubleshoot NFS Performance in Linux

Understanding Kafka Console Producer and Consumer in 10 Easy Steps

Popular Apache Kafka Architecture Explained Using 4 Basic Components

17 Useful Apache Kafka Examples on Linux (RedHat/CentOS 7/8)

How to Install Apache Kafka on Ubuntu 18.04

How to Install Apache Zookeeper on Ubuntu 18.04

Tutorial: How to do Elasticsearch Backup and Restore (v7.5)

Leave a Comment