Moving email sending function into a service.