Sending email from the command-line should not be complicated, so I’ve compiled a list of frequently used commands. I’m using Mutt instead of mailutils, since the latest version of the mail command mail (GNU Mailutils) 2.99.98 does not have support for the CC and BCC parameters directly.

We’re going to install the Mutt utility on Ubuntu 16.04. Do this:

apt-get update
apt-get install mutt

Run mutt -v to check the version after installation. We’re working with Mutt 1.5.21 (2010-09-15).

Sending Emails

This is the basic email command.

mutt -s "This is my subject." [email protected]

This will open an interactive panel so you can compose and configure your message. The shortcuts to navigate this interface are at the top, and the prompts are at the bottom. You can hit y to send your message when you’re done.

Parameters

The mutt command has some helpful parameters.

  • -s: Subject of the message.
  • -c: CC email address.
  • -b: BCC email address.
  • -a: File to attach.

Examples

Sending email with message body.

mutt -s "This is my subject." [email protected] <<< "This is my body."
mutt -s "This is my subject." [email protected],[email protected] <<< "This is my body."
echo "This is my body." | mutt -s "This is my subject." [email protected]
cat /tmp/message_body | mutt -s "This is my subject." [email protected]
mutt -s "This is my subject." [email protected] < /tmp/message_body

Sending email without message body.

mutt -s "This is my subject." [email protected] < /dev/null

Sending email with multi-line message body.

mutt -s "This is my subject." [email protected] <<EOF
This
is
my
body
.
EOF

Sending CC and BCC. Use the -c and -b flags to specify carbon-copy and blind-carbon-copy recipients.

mutt -s "This is my subject." [email protected] -c [email protected] -b [email protected] <<< "This is my body."

For sending attachments, just use -a with any of the above commands. Like so:

mutt -s "This is my subject." [email protected] -a /tmp/message_body < /dev/null
mutt -s "This is my subject." [email protected] -a /tmp/file_1.txt /tmp/file_2.txt < /dev/null

Some Use Cases

Email current disk usage report.

df -h | mutt -s "Disk Usage Report" [email protected]

Email current disk and memory usage report.

df -h > /tmp/report.log
free -m >> /tmp/report.log
mutt -s "Disk and Memory Usage Report" [email protected] < /tmp/report.log
mutt -s "Disk and Memory Usage Report (Attachment)" [email protected] -a /tmp/report.log < /dev/null