The mechanism of the Mannich reaction starts with the formation of an iminium ion from the amine and the formaldehyde. Please note, the mechanism shown below is NOT correct. The pKa of the protonated oxygen is approximately -2. The amine base would simply deprotonate the carbonyl and stop the reaction. Consequently, it is imperative that this reaction is performed at a pH of approximately 4-5. The correct mechanism should start with a nucleophilic attack by the nitrogen atom on the carbonyl carbon.