Mail Command Examples in Unix / Linux Tutorial

the mail command syntax is:

mail command options are listed below:

examples of mail commands: sending emails:

1. sending a sample email to the user

The basic functionality of the mail command on the unix or linux system is to send an email to the user.

The echo statement is used here to specify the body of the email. the -s option is used to specify the subject of the mail. the mail command sends the email to the user [email protected]

2. specifying the body in a file

You want to compose an email that contains 100 lines in the body. specifying the body with the echo statement is a tedious process. so write the body content to a file and send the mail using one of the following options:

here the body.txt file contains the body of the email. 3. send mail to more than one user you can send email to more than one user by specifying the users in a comma separated list.

4. using the cc and bcc option you can copy the emails to more users using the -c and -b options. Here is an example:

5. specifying the from address so far, the examples above send the emails with the from address as the logged in user. you can explicitly specify the source address with the -r option.

See Also:  How to Auto Archive Email in Gmail | Boxy Suite

6. attaching files. the mail command does not provide an option to attach files. there is a solution to attach files using the uuencode command. pipe the output of the uuencode command to attach files.

examples of mail commands: reading emails:

1. viewing all received emails just type the email then press enter to view received emails.

Another way to view emails is by using the -f option. this is shown below:

From the output above, you can see that it shows the From Address, Date, and Subject of the emails in the inbox. also displays the trailing ampersand (&). To return to the main prompt, type ctrl+z or ctrl+d depending on your operating system and press enter. ampersand notice allows you to read, reply, browse and delete emails.

2. reading an email.

To read the nth email, simply enter the email number at the ampersand prompt and hit enter. this is shown below:

this shows the details of the second email.

3. browse through the emails in the inbox. to go to the next email, enter the + symbol. To go back to the previous email, enter the – symbol at the ampersand prompt.

4. reply email. once you have read an email, you can reply to the email by typing “reply” and pressing enter.

5. email deletion. you can delete a read email by typing d and pressing enter. you can also specify the email numbers in the d option to remove them.

See Also:  Bizfluent

Leave a Reply

Your email address will not be published. Required fields are marked *