Add test coverage for the action mailer

Now there are no cosmetic changes (#14002). Removed few unused code and added test coverage.