Changes to email sending code