Wednesday, November 18, 2009

Mutt: Scripting mail

With 'mutt' we can generate e-mails and have them sent to our default e-mail address, in this case
mutt -s "Subject line here" < /path/to/message
is the correct command for this e-mail address. You can find more details at or the man page of mutt.

In the end, my script looks like this:
# Sends the IP address to default address
temp=`mktemp -t`
ifconfig ppp0 > $temp
mutt -e "set from=$from@$domain" -s "IP address - $HOSTNAME" "$to@$domain" < $temp

$HOSTNAME is set based off the hostname of the computer. In my case this name is specific to the location and is unique. This helps me know which school I'm contacting.
The other main addition is the "-e" command.
If you look online you'll find that in order to send from a specific domain, you need to set up a muttrc file. Since we're running a script, and it makes more sense to keep everything together, I decided it's better to just add the "set from=" command in the script instead of an outside file.
The "-e" command lets you do this. It must be in quotes, otherwise it'll throw an error.

This is also added to the ip-up script that is run when ppp0 makes a connection.

You'll then need to make sure that postfix is installed. The best way, is to set up postfix and have it send through a designated email address. I simply set up a "noreply" email address on our domain that I would log into to send the email.
You can find instructions here:

No comments:

Post a Comment