On this page
Sending Emails from Command Line
Introduction
There can be great utility in sending emails from the command line. Everyone has their own use case, and I’ll explain how it works.
Mail is one of the most commonly used commands for sending emails:
echo "My text body" | mail -s "My Subject" "xxx@mycompany.com" "mail@mail2.com" "mail@mail3.com"
I think this is clear enough. You can do whatever you want before the “pipe” and then send everything.
If you want to send an attachment, do this:
echo "see attached file" | mail -a filename -s "subject" email@address
or
cat filename | uuencode filename | mail -s "Email subject" user@example.com
Mutt
Mutt is not specifically dedicated to sending emails, but the advantage is being able to attach files. Here’s another small example:
echo "My text body" | mutt -x -a my_attachment -s "My Subject" "xxx@mycompany.com" "mail@mail2.com" "mail@mail3.com"
Last updated 21 Sep 2009, 13:26 CEST.