generate .mht file programmatically

前端 未结 4 1148
醉话见心
醉话见心 2020-12-31 11:03

Does anybody know how to generate .mht file programmatically in C#, with embedded images in it? The thing is i have realised that .mht files are capable of embedding images

4条回答
  •  忘掉有多难
    2020-12-31 11:31

    In a Windows environment you can do this directly by means of the CDO.Message COM component, which exposes the IMessage interface
    I dont know the details of importing COM objects in C# so I'll give you a quick example in C-like syntax:

    IMsgObj = CreateObject("CDO.Message")   // create the object
    IMsgObj.CreateMHTMLBody("http://www.example.com/") // convert the URL to MHTML
    IMsgObj.GetStream().SaveToFile("output.mht")  // save it to a file
    

    The CLSID of the CDO.Message components is {CD000001-8B95-11D1-82DB-00C04FB1625D}

    Keep in mind though, that this component is meant for generating e-mail messages (.eml file extension rather than .mht) which means JavaScript files are not included. Otherwise they are roughly equivalent.

提交回复
热议问题