move email middleware to messages component