Fix data writing to stream

There were problem with streaming data, when using embed images or while sending big message. Connection to SMTP server and email sending was an interrupted.
It was due to the fact that fwrite operations on non-blocking socket streams can be interrupted by the arrival of new packets.
After this fix writing continues  until all data is sent.