added code to send the emails