Snowy Owl Consulting

Using Mutt to automate email notices

Here's how to send email with full control over who it is from, who gets a copy, who it goes to, and what the body of the message is.

The key is to use mutt, a mail client that is already installed on many Linux systems. There are two steps to using it so that your email is sent as desired:

  1. Define an environment variable called EMAIL which contains the sender's identification.

  2. Invoke mutt from the command line with the proper switches.

Here's an example:

export EMAIL="Dan Coutu <dcoutu@boguscompany.com>"
mutt -c dcoutu@boguscompany.com -s "This a test message" joanie@bogusisp.net < myfile

This will send 'myfile' to Joanie and me, from me, even if I'm logged in as some other user (such as apache because this is running as from a CGI).

As you see I'm redirecting stdin from a file and this implies that you can just feed the message you wish to send into mutt's stdin and away it will go.


Copyright © 2002-2011, Snowy Owl Consulting, LLC

"));