mail(1)
Send and receive email messages from the command line.
Synopsis
mail [OPTION]... [recipient ...]Description
mail is a simple command-line utility for sending and reading email messages. It can be used interactively to read incoming messages or non-interactively to send messages with attachments from scripts and cron jobs.
When run without arguments, mail enters interactive mode and displays your inbox. When given recipient addresses, it opens a message composition interface where you can type a message body and send it.
mail supports piping data, reading from files, and adding attachments, making it useful for automated email notifications in shell scripts.
Common options
| Flag | What it does |
|---|---|
-s "subject" | Specify the subject line for the outgoing message |
-c address | Send a carbon copy (Cc) to the specified address |
-b address | Send a blind carbon copy (Bcc) to the specified address |
-a file | Attach a file to the outgoing message |
-S variable=value | Set a mail variable (e.g., -S [email protected]) |
-u user | Read mailbox for the specified user |
-f filename | Read messages from the specified mailbox file instead of default inbox |
-H | Print header lines only; don't display message bodies |
-e | Check if mail exists; exit with status 0 if mailbox has messages |
Examples
Send a simple email with subject from standard input
echo 'Hello, this is a test.' | mail -s 'Test Subject' [email protected]Send an email with a file attachment, subject from message.txt
mail -s 'Weekly Report' -a report.pdf [email protected] < message.txtSend email with Cc and Bcc recipients (enter message interactively)
mail -s 'FYI' -c [email protected] -b [email protected] [email protected]Open interactive mode to read messages from your inbox
mailRead the mailbox for user 'john'
mail -u johnRead messages from a specific mailbox file
mail -f /var/mail/archive.mboxPipe command output as email body to send disk usage report
df -h | mail -s 'Disk Usage Report' [email protected]Display the first 20 message headers from root's mailbox
mail -H -u root | head -20