Move the mailer constructor logic out of the plugin and in to a factory class for reuse.