The update to nodemailer requires different initialization.

@seanmonstar - would you mind reviewing this? The recent update to the nodemailer version required the mailer to be set up differently. While I was poking in the emailer code, I refactored things to be a bit more structured/understandable.


Do a refactor while I am at it to clean up the code.

fixes #4000