Added the logic to handle sending emails, emails not actually sent yet.