UNIX Tip of the Week

Command-line MAIL


Have you ever wanted to quickly mail a URL or a bit of program output to someone?
Rather than starting up pine, mutt, or exmh, try using mail next time.

SYNOPSIS
     mail [-s subject] [-c cc-addr] [-b bcc-addr] to-addr...
mail takes standard input as the body of the message, and mails it to the user(s) specified.


To mail a file foo.bar to your friend Joe:

mail joe < foo.bar


To mail a URL to joe (this time including a Subject: line),

echo "http://cm.bell-labs.com/plan9/" | mail -s "Plan9 O/S Homepage" joe
To send a CC to Jane, just include -c jane
To send to a list of recipients, use SPACES (not commas) to delimit the names:
mail dick jane alice jerry jip < SUSY_results.ps


You may find this to be useful in scripts, to mail yourself when a process ends, or to mail output data.

The syntax used in this example is for Linux.
On IRIX, there are two rather similar commands: mail and Mail. Mail is the more useful of the two, though it doesn't offer the -b or -c options.

And as always, I can't encourage you enough to man mail.


Revised: February 25, 2000