Lots of changes for email (keep connection alive, refactor templates out
etc.)