Added logic of sending emails