mailx

Enhanced mail command for sending and receiving Internet mail

TLDR

Send email (type body, end with Ctrl+D)
$ mailx -s "[Subject]" [[email protected]]
Send with body from pipe
$ echo "[message]" | mailx -s "[Subject]" [[email protected]]
Send from file
$ mailx -s "[Subject]" [[email protected]] < [message.txt]
Send with attachment
$ mailx -s "[Subject]" -a [file.pdf] [[email protected]]
Send with CC and BCC
$ mailx -s "[Subject]" -c [[email protected]] -b [[email protected]] [[email protected]]
Read mail
$ mailx
Read mail from a specific mailbox file
$ mailx -f [path/to/mbox]
Use SMTP server
$ mailx -S smtp=[smtp://mail.example.com] -s "[Subject]" [[email protected]]

SYNOPSIS

mailx [options] [recipients]

DESCRIPTION

mailx is an enhanced mail command for sending and receiving Internet mail. It is POSIX-compatible with extensions for MIME support, SMTP connectivity, S/MIME, attachments, and more features than basic mail.It handles both sending and reading email. When called without arguments, it reads the user's mailbox. When given recipients, it enters compose mode.

PARAMETERS

RECIPIENTS

Email addresses.
-s SUBJECT
Email subject.
-a FILE
Attach file.
-c ADDR
CC recipients.
-b ADDR
BCC recipients.
-r ADDR
Set From address.
-S VAR=VALUE
Set internal variable (e.g., smtp, from, smtp-auth).
-t
Read recipients from To/Cc/Bcc headers in the message.
-f FILE
Read from mailbox file.
-N
Inhibit reading system-wide startup file.
-H
Print header summary and exit.
--help
Display help information.

INSTALL

sudo zypper install mailx

CAVEATS

Multiple implementations exist (heirloom-mailx, s-nail, BSD mailx) with differing feature sets. SMTP configuration and attachment syntax varies between implementations. The -a flag means "attach file" in heirloom-mailx/s-nail but "set header" in BSD mailx.

HISTORY

mailx evolved from the original Unix mail command through Berkeley Mail. Modern implementations include s-nail (successor to heirloom-mailx) which adds MIME, SMTP, POP3, and IMAP support.

SEE ALSO

mail(1), mutt(1), sendmail(8)