Read and send mail

The mail program is a very basic command-line email utility that can be used to read mail or send mail to users. This program only supports reading the local email queue, not emails stored on remote servers.

To send emails using the mail command, you must provide options such as the subject, recipient’s address, carbon copy address, etc. To specify a subject, use the -s option. To set a carbon copy address, use the -c option. The recipient’s email address terminates the mail command’s line. After you type the mail command, the program waits for input. After you are done writting the message, you can signal the end of the message by pressing Ctrl+D.

Here is an example:

linux mail command

In the picture above you can see that we’ve sent an email with the subject Hello to the user bob. A carbon copy has been sent to the user jack.

To send e-mails to users on the same local mail server, you can specify only the username. However, if you want to send e-mails to users on another server or network, you must specify the full e-mail address.

 

Using the mail command with no arguments displays all messages in your mailbox, as shown in the picture below:

linux mail command readlinux mail command

After you view a message in your mailbox, the message is written to the file in your home directory (e.g. /home/bob/mbox). You can these messages by using the mail -f command:

linux mail f command

The mail command is in the /usr/bin directory and is linked to the mailx command, a newer version of the program.
Geek University 2022