You get emotional pain because you have identified with the mind. Shift your identification from the mind to the intellect. Assess the person or situation objectively and you will no longer get influenced. Go a step further and identify with Atman and the affectation will be zero.
A piece of iron is attracted and influenced by a magnet but not wood. The world is like the magnet, the mind is like iron which is influenced and the wood is likened to Atman. When you identify with the mind, you suffer. Connect with Atman and you will no longer experience pain.