views:

125

answers:

1

I have a ready generated MHTML as a byte array (from Aspose.Words) and would like to send it as an email. I'm trying to do this through CDOSYS, though am open to other suggestions. For now though I have the following:

        CDO.Message oMsg = new CDO.Message();
        CDO.IConfiguration iConfg = oMsg.Configuration;
        Fields oFields = iConfg.Fields;

        // Set configuration.
        Field oField = oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"];
        oField.Value = CDO.CdoSendUsing.cdoSendUsingPort;
        oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
        oField.Value = SmtpClient.Host;
        oField = oFields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
        oField.Value = SmtpClient.Port;
        oFields.Update();

        //oMsg.CreateMHTMLBody("http://www.microsoft.com", CDO.CdoMHTMLFlags.cdoSuppressNone,  "", "");
        // NEED MAGIC HERE :)
        oMsg.Subject = warning.Subject;             // string

        oMsg.From = "[email protected]";
        oMsg.To = warning.EmailAddress;
        oMsg.Send();

In this snippet, the warning variable has a Body property which is a byte[]. Where it says "NEED MAGIC HERE" in the code above I want to use this byte[] to set the body of the CDO Message.

I have tried the following, which unsurprisingly doesn't work:

oMsg.HTMLBody = System.Text.Encoding.ASCII.GetString(warning.Body);

Anybody have any ideas how I can achieve what I want with CDOSYS or something else?

+1  A: 

Please don't use CDO, it dates from an era when computers still used smoke signals to exchange emails. System.Net.Mail contains everything you need, MailMessage is your friend. Note its IsBodyHtml property.

Hans Passant
I did look at System.Net.Mail and MailMessage but it doesn't seem to support MHTML. And isn't it just a wrapper for CDOSYS anyway? CDOSYS at least seemed to have *some* support for MHTML, but it seems you have to use CDOSYS to generate the MHTML which is not really what I want.
mutex
You might be better off working from the assumption that few people that read this know what MHTML means.
Hans Passant