You can send an email directly from the command line using the mail command by typing the following:
mail <username>
For example, to send a message to postmaster, type the following:
mail postmaster <cr>
No prompt will be displayed. Start typing the message. When finished, press Return to get to an empty line and then press Ctrl+D to send the message, as follows:
This is a test [CTRL+D]
Now, if root logs in on another system that has been set up as a mail client, he will get the following message:
"You have mail."
mailx is similar to the mail command in that it is used from the command line. mailx is a bit more interactive than the mail command, however, in that it provides prompts. In this example, I’ll email a message to bill:
mailx bill <cr>
The system responds with this:
Subject:
I type in a subject as follows and press the Return key:
Subject: This is a test <cr>
I’m presented with a blank line where I can start entering the body of my email message. When finished typing the message, I press the Return key to go to an empty line and then press Ctrl+D. The EOT message is displayed, and the message gets sent:
This is a test to bill from root. <cr> [CTRL+D] EOT
Both mail and mailx are good utilities for sending basic email messages directly from the command line. They are good tools for emailing messages directly from a script. For example, you could write a script to run every day via crontab that watches file systems. You could set the script up to automatically email you when a threshold has been reached. You probably don’t want to use mail or mailx, however, for sending and receiving all of your email. A GUI-based email utility like dtmail is much easier and friendlier to use.