Sending E-mail

Sending E-mail

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.

mail

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:

1.
mail username@host.domain

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 susan@cool.domain.net   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$ 

2.
Enter a subject line and press .

mail responds by waiting for you to enter your message.

3.
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).

4.
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:

  • find ~ - name "*.mp3" mail -s "My

    MP3 files myaddress@host.domain &

    This pipes the output of the find command into mail . The & at the end of the command line runs the whole thing in the background (as we noted in Chapter 2).

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:

  • mail -s "here is the file"

    address@host.domain < memofile

    This passes the contents of the file to mail as the message body. (See "Redirecting stdin " in Chapter 2 for more on how the < operator works.)

    Unless the message is made up only of plain text (that is, no images or other non-text material), it will not show up properly. The mail command is very old and predates the common use of e-mail attachments. If you want to send anything besides plain-text e-mail from the command line, you should use pine .

Pine

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.



Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net