refactor generic mailer