refactored code, added smtp_timeout