When trying to send a message via the SMTP adapter in BizTalk we have the option of attaching messages as part of Multi-Part Messages. If the message being attached is too large the message will fail to send. In our application, we send email notifications of failed messages in BizTalk with the original message sent as an attachment.
An solution we devised was to compress the original message and attach it to the email. This solution, however, presented its own considerations.
We didn’t want to create a temporary directory on a server to create the compressed file in. We wanted to do all of the compression in memory.
Since we were compressing in memory we had to come up with a solution to attach the file to the email message.
The compression in memory is discussed in my posting on File Compression In Memory. …
File compression is nothing new to .NET. However, in many solutions it requires the developer to establish a file folder which they will write the compressed file to and later read from.
This solution cannot work if you want to compress and use the file in memory without writing to disk. An example of this could be on a server where you don’t particularly want to have random processes writing to and reading files.
Listed below is a solution we came up with for compressing a file in memory. We used an open source library SharpZipLib from sharpDevelop.net. There are other good options out there that could also be used. We found that using this library offered the most intuitive solution to creating the archive file.
The result will be a Stream which can be used to send the compressed data to an…