mailer.js refactoring, need testing