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 (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
mutt -v to check the version after installation. We’re working with
Mutt 1.5.21 (2010-09-15).
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.
mutt command has some helpful parameters.
-s: Subject of the message.
-c: CC email address.
-b: BCC email address.
-a: File to attach.
Sending email with message 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
-b flags to specify carbon-copy and blind-carbon-copy recipients.
For sending attachments, just use
-a with any of the above commands. Like so:
Some Use Cases
Email current disk usage report.
df -h | mutt -s "Disk Usage Report" [email protected]
Email current disk and memory usage report.