Refactor mail and log jobs