refactor email handling to separate module, convert smt to unittest