需求如下:将outlook另存为的.msg文件读取到内存中,并导出为pdf文件,请问如何读取这个.msg文件?提供代码最好,谢谢!

解决方案 »

  1.   

    先把下面网址里的内容看下。
    http://www.fileformat.info/format/outlookmsg/然后用FileStream写读取算法吧。这个还算好,以前写某些程序的打包格式哪才叫惨。得自己猜格式。哈哈
      

  2.   

    谢谢ls几位,自己搞定了,没这么复杂:1. 安装office07(估计03也可以,未试)
    2. 引用:using OutLook = Microsoft.Office.Interop.Outlook;(07版本是12.0)
    3. 示例代码:    OutLook.Application olApp = new OutLook.Application(); 
        OutLook.NameSpace olNS = myolApp.GetNamespace("MAPI"); 
        OutLook.MailItem olMail = default(OutLook.MailItem); 
        bool cancelled = false; 
        string sourcePath = "c:\xx.msg";
        string targetPath= "c:\xx.doc";//另存为doc文件
        
        olMail = myNamespace.OpenSharedItem(sourcePath); 
        olMail.SaveAs(targetPath, OutLook.OlSaveAsType.olDoc); //指定 save as 的类型
        olMail.Close(cancelled); //ref cancelled传进去的时候必须=false
        olMail = null; //注意此句必须,否则一直不会释放对象,导致msg文件被锁住,以后加载会报错if(!cancelled){
      //转换doc到pdf,不再详述
    }
      

  3.   

    so kind of LZ, just share the answer finaly. thanks
      

  4.   

    六楼(Mark2Win)OpenSharedItem在outlook2003里是没有的api,只有2007以上有