【发布时间】:2017-10-07 17:04:54
【问题描述】:
我正在尝试将 .msg 文件转换为 .txt。我有两个问题。
1)我一直在调查并发现 Microsoft.Interop Outlook 包,有一种方法可以提取 bodyHTML、To、Sent Date 和其他一些属性,但我觉得这是一个非常手动的处理,因为我必须修剪掉所有的 html 标签,例如
、 、a href 等...
这是我当前的代码...
MailItem mailItem = outlookApp.Session.OpenSharedItem(item) as MailItem;
TextFile textFile = new TextFile(); //collection of properties I am interested in
textFile.To = mailItem.To;
textFile.Subject = mailItem.Subject;
textFile.Sent = mailItem.SentOn.ToString();
textFile.Name = Path.GetFileNameWithoutExtension(item);
var atttach = mailItem.Attachments; //Really just want the names
textFile.Body = RemoveStuff(mailItem.HTMLBody); //manually removing all html tags
textFiles.Add(textFile);
Marshal.ReleaseComObject(mailItem);
有谁知道在 C# 中是否有更有效的方法或使用我不知道的 Interop 的方法?
2)如果我走互操作路线,有没有办法绕过 Outlook 中询问我是否可以访问 Outlook 的弹出窗口?如果我的目标是创建转换器,这似乎效率低下。
非常感谢任何帮助。
谢谢!
【问题讨论】:
标签: c# text outlook interop msg