Finished, but have not yet tested, the email code