EscapeChar none
in ~homeuser/.ssh/config to disableTable of Contents
An Introduction to Various BSD mailx style E-mail Clients on SDF
History
In the beginning.. there was mail, which was included in Unix 1st Edition in 1971 according to the ancient texts (manuals). At this time, Unix had no remote communication facility at all, so mail would simply write to other users' files on a single machine. As systems began to be networked mailx came on the scene with expanded features. Eventually the two merged; these days mail and mailx are one and the same program and enjoy near-universal presence across all flavors of Unix and Linux. For a bit more mailx history see the Heirloom Project.
Getting Started
One of the great features of mailx is it behaves like most traditional Unix commands; you can pipe the output of other commands to it or use it in a shell script or crontab(1). With just the default settings a user should be able to send a message to themselves or another account on the local system like so:
$ mailx localuser
The sender will generally be prompted to enter a Subject: after which they simply type their message then press CTRL+D
to signal End Of File (EOF) and off it goes.
To further automate sending simple messages the subject and an input file can generally be specified on the command line like so:
$ mailx -s "simple test" some_user < myfile
Most mailx implementations allow multiple addressees as well as CC / BCC recipients to be specified on the command line which makes it's fairly easy to automate the sending of regular broadcast-type emails.
Using mailx on SDF
There are many Mail User Agents (MUA) on SDF including at least 3 flavors of mailx:
- mail / mailx – the native NetBSD mailx with MIME extensions
- heirloom-mailx – formerly nail; supports MIME + POP3, IMAP & SMTP (not actively developed)
- s-nail / s-mailx – an actively developed fork of heirloom-mailx
Most likely the default SDF shell PATH
variable will give the native tools precedence over those installed via a package manager. This means typing mailx
will mostl likely run /usr/bin/mailx
(native mailx), not /usr/pkg/bin/mailx
(heirloom-mailx). A simple way to check:
$ which mailx /usr/bin/mailx => this shell checks native tool locations first
Similarly for man(1)
, the manpage reader; below is how to read each:
$ man mailx # native mailx documentation $ man -S pkg mailx # heirloom-mailx documentation $ man s-nail # s-mailx documentation
Users on the SDF cluster will find additional documentation under /usr/share/
:
- Mail Reference Manual –
/usr/share/doc/reference/ref1/mail/mail.txt
- Mail Command Reference –
/usr/share/misc/mail.help
- Mail Tilde Command Ref –
/usr/share/misc/mail.tildehelp
To read use any pager like more or less, or even the lynx browser.
Basic mailx Usage
Each of the 3 mailx programs are sufficiently different that beyond the very basics they need to be covered separately in this tutorial. That said, the following should work on all implementations:
mailx cmd | description |
---|---|
header | lists message headers; accepts range and +/- |
type | prints message(s); accepts range. |
forward | forwards current message with all headers |
delete | deletes mesages; accepts range |
compose a mew message; accepts multiple addrs | |
write | write message(s) to file; allows MIME splits |
reply | reply to sender(s); use Reply for just primary |
list | list all mailx commands |
Typing help
within an active mailx session will list the most common commands and their usage. Most mailx commands can be abbreviated to their first letter and several aliases exist, for example type
and print
are the same, so are file
and folder
. See the Mail Command Reference document for more info.
Similarly, in composition mode there are several tilde commands that are common to all mailx clients:
tilde cmd | description |
---|---|
~p | print current header and body of message buffer |
~f | read in a message; accepts range, curr. default |
~d | read in contents of dead.letter (DEAD) |
~m | read message in as ref.; usually prefixed with '>' |
~e | open message buffer in default editor |
~h | edit the message headers; use ~c, ~b for CC and BCC |
~r | read a local file into message buffer |
~?1) | list all tilde commands and their usage |
Once a composed message is ready to be sent an EOF (CTRL+D
) is entered on a new line (traditionally BSD mail also accepts a single “.” (dot) on a new line; enable the bsdcompat
option in the config file for this behavor). See the Mail Tilde Command Ref document and the manpages for additional info.