Add email code

Adds the code that actually sends the emails.