$linuxjunkies
>

mailx(1)

Send and receive email messages from the command line.

UbuntuDebianFedoraArch

Synopsis

mailx [-BDdEeHiNnv] [-s subject] [-c cc-addr] [-b bcc-addr] [-a file] [-S var=value] [recipient ...]

Description

mailx is a command-line mail user agent that allows you to compose, send, and read email messages. It provides an interactive shell for managing mailboxes and can also be used in scripts for automated mail delivery. When invoked without arguments, it reads incoming mail; when given recipients, it enters compose mode to send a message.

The command supports attachments, custom headers, and various formatting options. It is often used for system notifications, cron job reports, and shell script mail integration. Modern systems may use mailx as a wrapper around other mail systems like sendmail or postfix.

Common options

FlagWhat it does
-s subjectset the subject line of the message
-c cc-addrsend a copy to cc-addr (carbon copy)
-b bcc-addrsend a blind copy to bcc-addr (not visible to recipients)
-a fileattach a file to the message
-vverbose mode; print details about message transmission
-ndo not read the system mailbox on startup
-iignore tty interrupt signals (use in scripts)
-S var=valueset a variable (e.g., -S smtp=smtp.example.com)
-Hprint headers only; do not print message bodies

Examples

send a message from file message.txt with subject 'Hello World' to [email protected]

mailx -s 'Hello World' [email protected] < message.txt

pipe output from echo directly into mailx to send a simple message

echo 'System backup complete' | mailx -s 'Backup Report' [email protected]

send message with PDF attachment to client and CC the manager

mailx -s 'Invoice' -a invoice.pdf -c [email protected] [email protected]

send disk usage report output as message body

df -h | mailx -s 'Disk Usage Report' [email protected]

send with explicit SMTP server in verbose mode

mailx -v -S smtp=mail.isp.com -s 'Test' [email protected] < body.txt

read incoming mail without reading the system mailbox (interactive mode)

mailx -n

send alert log to primary recipient with a blind copy sent separately

mailx -b [email protected] -s 'Alert' [email protected] < alert.log

Related commands