How to send email alerts based on conditions?