Refactored sendmail