moved mail functions into a module