Command Line Mail

Here’s one for the book…:

I have a script that monitors a process and I want it to email my cellphone (to page me) if things don’t look just right. The problem is that just using “mail” or “mailx” in a script fails because my carrier divines whether or not my return address is real. Obviously a from field that looks like “root@localhost” is just not getting through.

What’s the solution? Enter “mutt”.

Mutt, it seems, will let you specify your from field in the ~/.muttrc file. Also, it works pretty much the same on the command line as mail or mailx. So, I set up mu ~/.muttrc like so:

set realname = "menotyou"
set from = "menotyou@myrealdomain.com"
set hostname = "myrealdomain.com"
set use_from = yes

And then, in the script I send mails like so:

echo "Wow I can send mail!" | /usr/bin/mutt -s "A present for you" myphoneaddr@provider.com

All in one line of course, but BINGO, all the sudden my cell phone springs to life at all hours of the night with information I don’t want to know 🙂

Enjoy!

Be Sociable, Share!

Leave a Reply

You must be logged in to post a comment.