updating mail sending logic