refactoring and add function
 - split function : send mail
 - add function : logging