Highly ordered mesoporous carbon nitride (CN) with an extremely high nitrogen content and tunable pore diameters was synthesized by using a new precursor with a high nitrogen content, aminoguanidine hydrochloride and mesoporous silica SBA-15 with different pore diameters as hard templates. Surprisingly, the N/C ratio of the prepared mesoporous CN (MCN-4: 1.80) was considerably higher than that of the theoretically predicted C3N4 nanostructures (1.33). This is mainly due to the fact that the CN precursor easily undergoes polymerization at high temperature and affords a highly stable polymer composed of a diamino-s-tetrazine moiety with a six-membered aromatic ring containing six nitrogen atoms that are linked trigonally with the nitrogen atoms. The obtained materials were thoroughly characterized by means of XRD, nitrogen adsorption, high resolution TEM, electron energy loss spectra, high resolution SEM, X-ray photoelectron spectroscopy, FTIR, and C, N, O, and S analysis. The results show that the MCN-4 materials possess a well-ordered mesoporous structure similar to SBA-15 with a high specific surface area and tunable band gap in the range of 2.25–2.49 eV. Interestingly, the pore diameter of the materials can be finely tuned from 3.1–5.8 nm by increasing the pore diameter of the hard-template SBA-15. The reaction temperature plays a critical role for the formation of MCN, and we found that 400 °C is the best condition to obtain MCN-4 with a high nitrogen content. We have further investigated the catalytic application of the MCN-4 materials towards Friedel–Crafts hexanoylation of benzene and compared the results with the mesoporous CN with less nitrogen content (MCN-1) and nonporous CN. Among the materials studied, MCN-4 showed the highest activity, affording a high yield of hexanophenone within a few hours, which is mainly due to the presence of free amine groups on the wall structure of MCN-4.