Send An Email From Linux Or UNIX Command Line Shell Easily

Sometimes, the system administrator might be required to send an emergency mail or a test mail message only using the command line interpreter or shell in Linux flavored OS and it might also be needed in the distribution of operating system such as CentOS, Ubuntu, Debian, Red Hat Fedora, FreeBSD, Open SUSE and etc. In such situations, you will find the mail command extremely handy one.

Actually “mail” is a command, which is used to receive and send mail massages in BSD operating system, UNIX and Linux. You could enter the following command to initiate the mail transfer procedure.


Of course, you should enter a valid email address in the place of

While typing the mail message body, you will be prompted to enter the subject for the mail by the system. The format would be like:

# mail
Subject: For Testing Only
This email is for testing the mail delivery system only.
^D (EOT)

After completing the typing of your email message, you just have to press Ctrl-D (it is shown like “^D” in the above example). It is used to represents the End of Text (EOT). You may or may not be prompted with the input request to enter any other recipients to send cc (carbon copy). It depends upon the operating system that you use. To skip this, just hit enter button or else accept the input, and the mail will be automatically delivered.

Tip: If the same system is used by the recipient and sender, then you may just omit the domain part (it will be as from the address, typing just user name only.

Furthermore, you could use switches and arguments of mail for sending the mail to directly avoiding any interactive input. For instance,

mail -s Test < /dev/null

The above command will send a blank email right away, which would have empty body to the address of recipient and having the subject name as “Test”. You could as well type “man mail” for extra arguments.