The sample is vaporised, turning it into a gas.
When an organic compound id placed in the mass spectrometer, an electron beam is fired at the gaseous molecules, knocking out an electron to form a positive molecular ion.
The detector detects the mass-to-charge ratio (m/z) of the molecular ion which gives the molecular mass of the compound which is shown on a mass spectrum.