Refactored custom mailer selection.
Added tests for custom mailer selection.