User Tools

Site Tools


Heirloom mailx (formerly nail)

Part of the now-defunct Heirloom Project, Heirloom mailx “provides traditional implementations of standard Unix utilities”, largely derived from original Unix material which was released as open source by Caldera and Sun Microsystems. Active development stopped around 2010 but some security patches have been applied to the NetBSD package version since and until something new comes along to break it it will likely remain available via PkgSrc. The various features and somewhat interesting history of Heirloom mailx is available on it's homepage.

Documentation and Features

The Heirloom mailx(1) manpage1) is the best place to learn all it's features but the standouts are:

  • POP3/IMAP/SMTP support
  • account-specific folder-hooks
  • definable macros
  • command and folder aliases
  • threading that actually works

There is also some rudimentary Bayesian filtering for dealing with junk mail, a drafts command for message templates, and even some support for encrypting/decrypting messages.


Avoiding name collision

Heirloom mailx installs as /usr/pkg/bin/mailx which may cause name collision with the native NetBSD mail/mailx client so it's a good idea to create a command alias for your SDF shell:

alias nail='/usr/pkg/bin/mailx'   # sh, ksh, pdksh, bash shells
alias nail '/usr/pkg/bin/mailx'   # csh & tcsh shells

Typing nail (the old client name) will now launch Heirloom mailx. Adding the appropriate alias to your shell's configuration file will make it available each time you log in. A launch script placed under ~/bin/ is another option.


The default user configuration file for Heirloom mailx is ~/.mailrc, unfortunately also used by the native NetBSD mail(1) client. If you never plan to use native mail(1) then you can go ahead and put all your settings in ~/.mailrc ; chances are the native mail(1) will just ignore any settings it doesn't understand. A somewhat better option which maintains settings separation is to create a minimal ~/.mailrc and add the following to it:

 set NAIL_EXTRA_RC=~/.nailrc

This will allow occasional / accidental use of the native mail(1) client and keeps all the “nail-specific” settings in ~/.nailrc. Alternately, it's possible to unset MAILRC and set NAILRC (shell environment variables) on-the-fly via a launch script for settings separation.

A basic SDF specific Heirloom mailx configuration (using both ~/.mailrc and ~/.nailrc):

## ~sdfuser/.mailrc
# Set top of mail folder tree to ~/mail:
set folder=mail
# Tell Heirloom mailx where to get additional configurations:
set NAIL_EXTRA_RC=~/.nailrc
## ~sdfuser/.nailrc file - use with /usr/pkg/bin/mailx
# Note:
# Set variables _persist_ until the session ends
# unless unset or reset.  Type 'set' to display
# current settings.
# Use alternate SMTP server (bypasses default SMTP):
#set smtp-auth="login"
#set smtp-auth-user="myacct"
#set smtp-auth-password="secret"
#set smtp=smtps://
# Set SSL Cert check method ("ask" is default).
# Will likely need "ignore" for accessing alternate
# SDF accounts when the SSL certs are expired.
#set ssl-verify="ask"
set ssl-verify="ignore"
#set ssl-no-default-ca
#set ssl-v2-allow
# Set directory where "folders" should look for mail folders
# (generally not needed if set in ~/.mailrc)
#set folder=mail
# Set MBOX (defaults to ~/mbox):
#set MBOX="~/mail/Saved"
# Have nail retain copies of outgoing msgs: 
set record="~/mail/Sent"
# Set dead.letter location (default is ~/dead.letter)
#set DEAD="~/mail/dead.letter"
# Retain the specified headers:
retain User-Agent bcc cc date from subject to
# Only retain the specified headers when saving messages:
saveretain bcc cc date from subject to
# Start regardless of whether msgs are in /var/mail/<user>:
set emptystart
# Set From: and ReplyTo: header fields:
# (default is your GECOS data)
#set from="SDF User<>"
#set replyto=" (Me Too)"
# Set AUTOSORT criteria:
#set autosort=thread
# Set signature file:
#set signature="~/.signature-nail"
# Have original msg text quoted in Replies:
set quote
# Specify what should be prompted for before sending msgs:
set askcc
set askbcc
set askattach
# Turn off autoprint so that 'd' _doesn't_ print the next message:
#unset autoprint
# Have html-based msgs piped thru lynx:
set pipe-text/html="lynx -dump -nolist -stdin"
shortcut saved +Saved
shortcut sent  +Sent
shortcut draft +Draft
# (note: cc/bcc mailings need to have at least one To: entry)
alias hop-list	hoppy@mud.bog \
		mrwarts@mud.bog \
alias bounce
# *** ALIASES ***
alias gopher		"Gopher Project Discussion <>"
alias nail-devel
alias netbsd-users	"NetBSD Users list <>"
# run by typing 'call <macro>' or using folder-hooks
# home - return to /var/mail/$USER and reset applicable variables.
#        Useful for getting back to local mail folders from IMAP accts.
define home {
        fi /var/mail/$USER
        set folder="~/mail"
        set record="~/mail/Sent"
        shortcut saved +Saved
        shortcut sent  +Sent
        shortcut draft +Draft
	set from="SDF User<>"
	set replyto=" (Me Too)"
# uas - Unset Alternate SMTP variables
define uas {
	unset smtp-auth
	unset smtp-auth-user
	unset smtp-auth-password
	unset smtp
# *** Remote IMAP ACCounts Section (no POP3) ***
# Note: ALL outgoing messages are processed LOCALLY unless an
# alternate MTA/SMTP server is set globally (see defaults above)
# or within an 'account'. Also, variables set in IMAP accounts
# persist until session endsunless unset/reset.  Type 'set' to see
# current settings, 'ac' for defined accounts.  IMAP accounts are
# not cached locally unless "imap-cache" is set.
# Set local caching of remote IMAP accounts:
#set imap-cache="~/mail/.imap-cache"
# Typical SDF user IMAP acct setup w/ SSL encryption:
account sdfuser2 {
	set folder=imaps://
	set record=+Sent
	shortcut sent +Sent
	shortcut saved +Saved 
	set from="SDF User2<>"
	set replyto="SDF User2<>"
### note: due to 2022 Gmail policy change this no longer works ###
# Typical Gmail IMAP/SMTP w/ SSL setup
# (need to enable IMAP access first)
account gmail {
        set hold
        set folder=imaps://gmail.user\@gmail\
        shortcut sent "imaps://[Gmail]/Sent Mail"
        shortcut spam "imaps://[Gmail]/Spam"
        set record=sent
        set from=""
        set replyto=""
        set password-gmail.user\@gmail\"**********"
        ## gmail SMTP server stuff:
        set smtp-gmail.user\@gmail\.com=smtps://
        set smtp-auth-user-gmail.user\@gmail\.com=""
        set smtp-auth-password-gmail.user\@gmail\.com="**********"
use $ man -S pkg mailx to ensure you are reading Heirloom mailx documentation
heirloom_mailx.txt · Last modified: 2022/06/26 15:14 by zilog