Type III radio bursts are radio emissions associated with solar flares. They are considered to be caused by electron beams travelling from the solar corona to the solar wind. Magnetic reconnection is a possible accelerator of electron beams in the course of solar flares since it causes unstable distribution functions and density inhomogeneities (cavities). The properties of radio emission by electron beams in an inhomogeneous environment are still poorly understood. We capture the nonlinear kinetic plasma processes of the generation of beam-related radio emissions in inhomogeneous plasmas by utilizing fully kinetic particle-in-cell code numerical simulations. Our model takes into account initial electron velocity distribution functions (EVDFs) as they are supposed to be created by magnetic reconnection. We focus our analysis on low-density regions with strong magnetic fields. The assumed EVDFs allow two distinct mechanisms of radio wave emissions: plasma emission due to wave–wave interactions and so-called electron cyclotron maser emission (ECME) due to direct wave–particle interactions. We investigate the effects of density inhomogeneities on the conversion of free energy from the electron beams into the energy of electrostatic and electromagnetic waves via plasma emission and ECME, as well as the frequency shift of electron resonances caused by perpendicular gradients in the beam EVDFs. Our most important finding is that the number of harmonics of Langmuir waves increases due to the presence of density inhomogeneities. The additional harmonics of Langmuir waves are generated by a coalescence of beam-generated Langmuir waves and their harmonics.