The Haiku/BeOS Tip Server
Tips and tricks for Haiku/BeOS users

Send mail from the command line

Contributed by: Scot Hacker
This tip is valid for: Both BeOS and Haiku

BeOS does not include a full-blown command-line mail client (though you can download pine if you need it), but it does let you send off quick messages and text attachments if necessary. Try this:


mail -s "Howdy!" someone@somewhere.com

[Enter message body here]

When done with your message, tap Ctrl-D. This sends an EOF (end of file) mark, which sends the message, using the settings established in the E-mail preferences panel. If you want to send an existing text file as the message body, use:


mail -s "Howdy!" someone@somewhere.com < /path/to/file.txt

Note however that if you do this with a binary, rather than a text file, the binary will end up in the message body, not as an attachment.


Roman Filippov (rxf at alkor dot ru) adds:

The mail utility can also take two flags for setting CC: and BCC: addresses:

 -c someone@somewhere.com

and

-b someone@somewhere.com

You can also list as many recepients as you wish on the command line. (e.g.: mail -s "Hello!" first@somewhere.com second@somewhere.com third@somewhere.com) This is equivalent to entering multiple recepients in the To: field of a GUI mail client.

It’s also possible to send a binary file using mail, but it takes a bit more work, as you’ll need to convert the binary to text format with uuencode:

mail -s "Hello!" someone@somewhere.com < uuencode  /path/to/file.zip
 remote_file

where remote_file stands for the file name which will be created by the decoder on the recipient computer, and /path/to/file.zip is the path to the binary file you wish to send.

To decode the file on the recepient side type:

 uudecode < received_e-mail_file_name 

These commands, paired with attribute manipulation utilities and grep, can be used to build powerful script-based mail processing systems similar to those found in commercial mail clients.

Posted in Terminal


(comments are closed).