Factored out all the writes to use a helper method to allow for nicer error checking.
Close the connection when finishing the e-mail.
Removed unused import.
Fix CLRF typo to CRLF.