refactor mailer