This happens through the connection cord, that has 3 wires: 2 wires are used for power supply. The third wire is used to 'ground' the metal case, by connecting it to a special pin from the wall socket. The eletrical installation of the building connects all these ground pins to earth.