If your Mac OS X system is connected to the Internet, you can easily send e-mail from the command line using the mail command.
The mail command lets you compose and send e-mail from the command line ( sendmail , on the other hand, is server software for transporting messages). It can also be used for reading e-mail if your Mac is set up to receive mail, but we don't cover that here. Instead, we cover the pine program, a better tool for reading e-mail from the command line, in Chapter 15, "More Open-Source Software."
To send e-mail from the command line:
You give the mail command one argument: the address you want to send to.
The mail command responds by prompting you for a subject. Figure 4.36 shows the complete process of sending e-mail from the command line.
Figure 4.36. Sending e-mail from the command line.
localhost:~ vanilla$ mail firstname.lastname@example.org Subject: Is it soup yet? This is the message body. You must press enter at the end of each line. When you want a blank line press return twice. . EOT localhost:~ vanilla$
Enter a subject line and press .
mail responds by waiting for you to enter your message.
Enter the body of your message.
Note that mail lacks any kind of fancy editing capability. You must press at the end of each line (there is no automatic word wrap).
When you're done, type a period on a line by itself and press .
That is how mail knows you are done with your message. mail responds as shown in Figure 4.36 with EOT ( End of Transmission ).
Your e-mail is on its way, and you get a shell prompt back.
Any command that produces text on stdout can be piped into mail . You can specify a subject on the command line with the -s option ( s for subject ).
A common reason for piping command output into the mail command is to run a command that takes a while to finish, pipe it into mail , and run the whole command line in the background (see Chapter 2). This allows you to get back to a shell prompt and get on with your work, and eventually receive e-mail when the process is done. You might do this if you want to find all the MP3 files in your home directory and e-mail yourself a list.
To pipe output from any command into mail:
Another useful trick with mail is to take the message body from a file by redirecting stdin .
To take the message body from a file:
Pine is a command-line e-mail program that takes over your whole Terminal window (though it is a "full-screen" program, it won't take over your whole Mac screen, just the Terminal window you run it from). It can handle e-mail attachments.
Pine was developed as an easier-to-use alternative to another full-screen command-line e-mail program, called elm . The name Pine stands for Pine is not elm . (The Pine program is capitalized, the pine command is not.)
We cover the installation and use of Pine in Chapter 15.