[task] refactore mail and template function, update controller tests