Friday, October 1, 2010

sending email from OpenWRT 10.03 Backfire (on boot)

My OpenWRT 10.03 Backfire isn't entirely stable when running transmission, and I would like to send simple notification emails to myself from my OpenWRT router whenever OpenWRT rebooted.

I'm accustomed to the "mail" command line program, but it is neither installed nor available in OpenWRT. Doing some digging with opkg and grep, I found a program called ssmtp that seems to do the job.

Installed ssmtp with the usual "opkg install ssmtp", and a little further digging led to finding the configuration file in /etc/ssmtp/ssmtp.conf. In my case, my ISP didn't require any security, so I simply set the "mailhub" option to my ISP's SMTP's server.

However, sending a test email to myself threw up the following error:
root@openwrt:/etc/ssmtp# echo test | ssmtp -s "test"
 ssmtp: 553 #5.5.4 Domain required for sender address

I guess my ISP's mail server insists on the sender domain being filled in, so I also set the "rewritedomain" option. (I also set the "hostname" option.)

Lastly, to accomplish my aim of sending an email to update me when  OpenWRT reboots, I added the following line to "/etc/rc.local".

echo "Subject:`hostname` booted at `date -Iminutes | sed -e 's/T/ /' | sed -e 's/+.*//'`" | ssmtp

The results are good enough for me. I now receive an empty email with a subject line in the form of "hostname booted at 2010-10-01 10:59" whenever OpenWRT reboots.

Now to the much more complicated task of figuring out if transmission/screen/top or some other background process is causing the spontaneous reboots. :(

1 comment:

Anonymous said...

A LuCI interface with common notification triggers would be very handy for us!
We'll get it soon hopefully!
Thanks for your experience sharing.