Quit MacOS Mail.app safely
It is very unlikely, but Mail.app that comes with MacOS is sometimes very buggy. Often it does not quit safely, and you have to kill it using Activity Monitor. It is especially annoying when it prevents computer from Shutdown. There is one trick, that at least for me - works every time. Before you quit the Mail.app - turn all accounts offline:
Wait until all accounts move to offline mode (Flash sign at the end of account) and quit Mail.app.
Next time when you start Mail, you should put accounts to online mode, by pressing Shift+Cmd+N (Get New Mail).
Obviously there is some asynchronous function in the application, that refreshes the content of your mail accounts, running in background and prevents application to quit. (for me this came with MacOS Lion release - before I had never experienced such behavior).