The only difficult part of that is getting a command-line mailer.
I've used postie in the past with good success, and at the time it was free. I now see they charge $15 for it.
However, there's anohter command-line mailer called bmail which seems to work as well.
So you code would look something like this: