Fix email code & tests

Sorry I took so long to submit this!