refactoring sendmail plugin