Adding email functionality

Adding a bunch of functionality to this script. It is really no longer
just a POST hook, it also sends emails. This is customized for
Silversky so there are a lot of things to clean up. I just decided
to commit since its been a few months and I don't want to lose the
work I've done.