Let $M \subset \mathbb{C}^N$ be a generic real-analytic submanifold of finite type, $M' \subset \mathbb{C}^{N'}$ be a real-analytic set, and $p \in M$, where we assume that $N, N' \geqslant 2$. Let $H: (\mathbb{C}^N, p) \to \mathbb{C}^{N'}$ be a formal holomorphic mapping sending $M$ into $M'$, and let $\mathcal{E}_{M'}$ denote the set of points in $M'$ through which there passes a complex-analytic subvariety of positive dimension contained in $M'$. We show that, if $H$ does not send $M$ into $\mathcal{E}_{M'}$, then $H$ must be convergent. As a consequence, we derive the convergence of all formal holomorphic mappings when $M'$ does not contain any complex-analytic subvariety of positive dimension, answering by this a long-standing open question in the field. More generally, we establish necessary conditions for the existence of divergent formal maps, even when the target real-analytic set is foliated by complex-analytic subvarieties, allowing us to settle additional convergence problems such as e.g. for transversal formal maps between Levi-non-degenerate hypersurfaces and for formal maps with range in the tube over the light cone.