I’m not going to go all Miss Manners on your ass and get into the social intricacies and delicate situations that surround thank-you note writing, as I was taught that a solid thank-you note will transcend all complicated situations—and I have seen no evidence to the contrary.
There is a six-point formula to the proper thank-you: Learn it, know it, memorize it, and it will never fail you.