integrated a state machine to send email notifications