Support for HTML emails

Supersedes PR #293, code rebased and updated to fix the context problem in `password_reset`