$linuxjunkies
>

mail(1)

Send and receive email messages from the command line.

UbuntuDebianFedoraArch

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

FlagWhat it does
-s "subject"Specify the subject line for the outgoing message
-c addressSend a carbon copy (Cc) to the specified address
-b addressSend a blind carbon copy (Bcc) to the specified address
-a fileAttach a file to the outgoing message
-S variable=valueSet a mail variable (e.g., -S [email protected])
-u userRead mailbox for the specified user
-f filenameRead messages from the specified mailbox file instead of default inbox
-HPrint header lines only; don't display message bodies
-eCheck 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.txt

Send 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

mail

Read the mailbox for user 'john'

mail -u john

Read messages from a specific mailbox file

mail -f /var/mail/archive.mbox

Pipe 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

Related commands