Existence and nonexistence of extremal functions for sharp Trudinger-Moser inequalities