Sending Email with mail
Despite mail's unintuitive interface and features, it is a great program to use if you just want to dash off a quick message without fussing with niceties. As Code Listing 11.3 shows, you can send messages while in mail or from the shell prompt. You can also use mail to send files fairly easily.
Code Listing 11.3. Using mail, you can dash off a quick note by including the recipient's address and the message text.
[ejr@hobbes ejr]$ mail debray Subject: You're in big trouble now! So, anyway, Winchester had perched himself on my stereo turntable (those were sooooo low-tech, weren't they?!). He was waiting for me to turn on the stereo so he could go back to sleep while spinning in circles. I used to let him sleep that way at night. Well, that was until one night when the lid closed on him... EOT [ejr@hobbes ejr]$
To Compose and Send a Message Using mail:
At the shell prompt, type mail followed by the recipient's address. If you want to send email to multiple addresses, just separate them with commas but no spaces, as in mail firstname.lastname@example.org, putz2@ raycomm.com.
If you're already in mail, just type m followed by the address or addresses, like m email@example.com,firstname.lastname@example.org.
So, anyway, Winchester had perched himself on my stereo turntable (those were sooooo low-tech, weren't they?!). He was waiting for me to turn on the stereo so he could go back to sleep while spinning in circles. I used to let him sleep that way at night. Well, that was until one night the lid closed on him...
Type in your message text (see Code Listing 11.3).
Announce that you're done with either a . (dot) by itself on the last line or with , and the message will zip off to the recipient(s).
To send text files with mail:
mail email@example.com < sendit.txt
At the shell prompt, type mail followed by the recipient's address. Then use < and the filename to redirect the file (< sendit.txt), which tells Unix to send the file to the address provided (Code Listing 11.4).
Code Listing 11.4. To send a text file through the mail, you just redirect the file to mail.
[ejr@hobbes ejr]$ mail firstname.lastname@example.org < sendit.txt [ejr@hobbes ejr]$
See Scheduling Regularly Occurring Jobs with cron in Chapter 9 for a spiffier way of using mail to send messages directly.
See the section in Chapter 1 called Redirecting Output for a refresher on redirection.
You'll notice that the mail interface on some systems does not provide for a subject line. On some systems, you can add one by including -s plus the subject text, like this: mail -s "An old Winchester story...dumb cat!" email@example.com.
You can accomplish all of these command-line mail sending options with mutt as well as mail, but you get added benefits with mutt, including being able to send attachments. For example mutt s "Sending that file" -a bigolefile.tgz suggest @example.com < /dev/null will do the whole nine yards at once, including attaching the big ol' file. Don't try that with mail!