I think the "when" part of the question has been well-answered, so I will only comment on formatting and style, some of which has also been addressed.
One thing I have trouble with when emailing people is keeping my emails short. But it is much, much better, especially when emailing a busy math professor, to keep your email to one page in Pine (yes, lots of math professors still use Pine). So introduce yourself briefly --- "I am an undergraduate at Tech U interested in XYZ" suffices. Using formatting, like bulleted and numbered lists if you have more than a unique question, never hurts.
At least at first, the other important thing to do is be "academic professional". My rule when emailing anybody is to use their full name in the "Dear So-and-so", where "full name" means whatever's at the top of their academic website. Depending on the context, honorifics like Prof. and Dr. are more or less appropriate. I sign my emails with my first name, and then include a very short "sig file" with my full name, institution, and email address, and only the first time. For future correspondence, I'll use whatever name the person writing to me uses in their signature.