I want to create a multipart MIME message out of some part data that I have available from some streams (eg open file handle) and I want the resultant multipart MIME message to be sent out through a stream (eg network port as part of HTTP connection).
However, these parts are numerous GB in size so I don't want to have to hold them in memory, and I don't want the multipart MIME message to ever need to be fully in memory.
So how can I create multipart MIME message without holding it in memory, ie streaming in the parts and having it streaming out the constructed message 'on the fly'?
I'd like to use a 3rd party MIME library but don't know if any support streaming like this, and I'm reluctant to author my own.
Any recommended practice?
After much further studying (inspired by MimeKit
example above) that the .Net HTTP classes support what I was looking for in a similar way to how MimeKit
does.
Create a MultipartContent
and add parts using StreamContent
, then get a stream for the multipart message using MultipartContent.ReadAsStreamAsync
and the part streams are not read until the multipart streaming needs it. This means (from monitoring process size) the original parts are never completely in memory at any time, nor is the multipart message.