mailx(1)
Send and receive email messages from the command line.
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
| Flag | What it does |
|---|---|
-s subject | set the subject line of the message |
-c cc-addr | send a copy to cc-addr (carbon copy) |
-b bcc-addr | send a blind copy to bcc-addr (not visible to recipients) |
-a file | attach a file to the message |
-v | verbose mode; print details about message transmission |
-n | do not read the system mailbox on startup |
-i | ignore tty interrupt signals (use in scripts) |
-S var=value | set a variable (e.g., -S smtp=smtp.example.com) |
-H | print 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.txtpipe 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.txtread incoming mail without reading the system mailbox (interactive mode)
mailx -nsend alert log to primary recipient with a blind copy sent separately
mailx -b [email protected] -s 'Alert' [email protected] < alert.log