Fix socket code so that email isn't sent until all data has been streamed.  Remove file after finished emailing.