A man accused of attempting to murder his wife said he stabbed her in a "moment of madness" after reading messages she sent her boss saying she was going to leave him, a court has heard.