Question

I'm working on a product that creates MS Word output by generating an HTML document with the appropriate bits of Word CSS and XML magic embedded in it. I now need to embed RTF (images and styled text) in the document, and so am looking at the multipart HTML generation features in .NET.

I'd like to generate the MHTML document by converting the RTF snippets into images in memory, and then just embedding the Base64-encoded data directly into the MHTML object. So far, I can't find any .NET solutions to do that.

The MS CDO stuff is promising, but it looks like the only way to create an attachment is to provide a URL to the data and use AddRelatedBodyPart() to add it to the object.

The System.Net.Mail package also looks compelling (as documented here and in a previous question here), but I don't see a straightforward way to convert the generated mail object to a string -- the API seems to be focused around sending mail messages, not generating files.

Right now, I'm pushing forward with an approach that uses CDO and temporary directories, but I'm unhappy with that as a long-term approach. Any better suggestions?

Was it helpful?

Solution

There hasn't been a lot of demand for the ability for System.Net.Mail to send its output to some sort of stream defined by the user but it's been talked about. Can you give me more info about your scenario? I'd like to know how people are using this in terms of justification for adding this feature.

I think you could use reflection to redirect the output stream from a FileStream to some other stream prior to sending the message. Most of the code in System.Net.Mail uses decorators around Stream objects so I suspect that it would be possible but I don't know reflection well enough to give you a good code snippet on how to do this. Also, System.Net.Mail uses its own base64 encoder so it's plenty fast. I tweaked a few things for .Net 4.0 also so you'll probably get even better performance from it although I doubt it would be noticable.

OTHER TIPS

The Base64 encoding support in .NET is not very fast, and System.Net.Mail is not general-purpose. I wound up using CHilkat S/MIME and it worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top