prevent duplicated sending e-mail, close cursors, refactoring, send email without attachment