how to set up sending mail from the command line

Often times I want to send emails to myself when a job is done or when something happens on the computer/server. Using the command line is the most portable and obvious as most software I run (eg, R) can execute from it.

This site shows how to use mail and mutt to send emails from the command line, but does not show how to set things up. Setting up actually took me a long time to figure out, as I wasn’t familiar with Mail User Agent (MUA), Mail Transfer Agent (MTA), etc. This site can help clear things up regarding those issue.

mailutils contain the mail command, which allows one to send mail but not attach files. mutt is an MUA that allows one to send mail from the command line and attach files. msmtp is an MTA that we can use with mail and mutt (mutt v1.5.x and above has it’s own built in smtp capabilities).

Note that to use TLS with msmpt, you need to set the certificate file. On a debian-basd system, you can find it in the /usr/share/ca-certificates/ directory, which has many. See below for references.

This site shows how to set up mutt with msmtp. This site shows how to set things up, along with the certificate stuff. More on certificate here. This will tell more on how to use the built-in smtp of mutt. The wiki of course has more information.

UPDATE 8/24/2011: From this post, use mail from bsd-mailx instead of mailutils to have the mail command working instead of the error msmtp: no recipients found.

UPDATE 11/13/2011: If you want to be able to email as the root user, make sure these instructions are set up for the root user’s home directory, /root/.

Wow, I used a tutorial telling me to install mailutils for beeing able to use “mail” command.
I got exactly that weird failure you are talking about (“msmtp: no recipients found”)…
It took me hours searching the internet to finally find relieve with this blog post on your page telling me to use bsd-mailx instead of mailutils…