Let M⊂CN be a generic real-analytic submanifold of finite type, M′⊂CN′ be a real-analytic set, and p∈M, where we assume that N,N′⩾2. Let H:(CN,p)→CN′ be a formal holomorphic mapping sending M into M′, and let EM′ 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 EM′, 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.