We obtained high resolution ELODIE and CORALIE spectra for both components of 20 wide visual binaries composed of an F-, G- or K-dwarf primary and an M-dwarf secondary. We analyse the well understood spectra of the primaries to determine metallicities ([Fe/H]) for these 20 systems, and hence for their M dwarf components. We pool these metallicities with determinations from the literature to obtain a precise (+- 0.2 dex) photometric calibration of M dwarf metallicities. This calibration represents a breakthrough in a field where discussions have had to remain largely qualitative, and it helps us demonstrate that metallicity explains most of the large dispersion in the empirical V-band mass-luminosity relation. We examine the metallicity of the two known M-dwarf planet-host stars, Gl 876 (+0.02 dex) and Gl 436 (-0.03 dex), in the context of preferential planet formation around metal-rich stars. We finally determine the metallicity of the 47 brightest single M dwarfs in a volume limited sample, and compare the metallicity distributions of solar-type and M-dwarf stars in the solar neighbourhood.