SMTP and error handling fixes