The difference ($E_2-E_1$)in electronic energy levels give the energy that the photon would have if the atom were held stationary. If the atom is allowed to recoil, the photon energy will be ($E_2-E_1$) minus the recoil energy.
But the recoil energy is only about $10^{-9}$ of the photon energy, so the reduction in photon energy is pretty negligible!
$$E_{k\ atom}=\frac{p^2}{2m_{atom}} = \frac{1}{2m_{atom}} {\left(\frac {h} {\lambda}\right)}^2=\frac{1}{2m_{atom}\ c^2} {\left(\frac {hc} {\lambda}\right)}^2=\frac {E_{phot}^2}{2m_{atom}\ c^2} $$