fix logic to send mail