Obviously you were presenting the words "Dear Prof. Smith"
as part of your answer, rather than issuing a greeting.
This distinction is known as the use–mention distinction.
It's conventional, when you mention words, to quote them.
If you had quoted the words you were mentioning
(by either of the common methods), you would not have had a problem,