moved mail code to service class