added logging of exception and mail messages