简体   繁体   English

将txt文件转换为C#VSTO加载项中的Outlook MailItem

[英]converting txt files to Outlook MailItem in C# VSTO Add-in

I am writing an Add-in solution for Outlook 2010 using Visual Studio C# 2010. Actually i'm going to implement a Bayesian spam filter which classify emails based on their contents. 我正在使用Visual Studio C#2010为Outlook 2010写一个外接程序解决方案。实际上,我将实现贝叶斯垃圾邮件过滤器,该过滤器根据邮件的内容对邮件进行分类。 my problem is that the public datasets available on the internet are all txt files and I need them to be converted in Outlook MailItem (Outlook Item). 我的问题是Internet上可用的公共数据集都是txt文件,我需要在Outlook MailItem(Outlook项目)中进行转换。 I test different tips to cast txt files to Outlook.MailItem but none of them work.for example: 我测试了将txt文件转换为Outlook.MailItem的不同技巧,但是它们都不起作用,例如:

Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            Outlook.MAPIFolder sourceFolder = inBox.Folders["non_spam"];
            Outlook.MAPIFolder destFolderInbox = inBox.Folders["testingNonSpma_inbox"];
            Outlook.MAPIFolder destFolderJunk = inBox.Folders["testingNonSpam_junk"];
            Outlook.Items items = (Outlook.Items)sourceFolder.Items;
            Outlook.MailItem mailItem = null;
            try
            {
                foreach (object eMial in items)
                {
                    ***mailItem = eMial as Outlook.MailItem;
                   // OR this way mailItem = (Outlook.MailItem) eMail;***
                    //Tokenize mail item
                    string tokenString = Tokenize(mailItem);

                    //Analyze and deliver to inbox\testingSpam_inbox or inbox\testingSpam_junk
                    bool isSpam = Analyze(tokenString);
                    if (isSpam)
                    {
                        mailItem.Move(destFolderJunk);
                    }
                    else
                    {
                        mailItem.Move(destFolderInbox);
                    }
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show("Error in class ThisAddin, Method buttonClassifyNon_Spam\n Subject:" + mailItem.Subject + ex.Message);
            } 

always different errors happen, like: can not convert System.__COM object to Outlook.MailItem interface and so on. 总是发生不同的错误,例如:无法将System .__ COM对象转换为Outlook.MailItem接口,等等。 (I checked different methods mentioned in this site and other ones, but no succeed) because of the large number of txt files in datasets, I can't manually open each and copy the contents in a Outlook New Mail. (我检查了本网站中提到的其他方法以及其他方法,但没有成功),因为数据集中的txt文件数量很多,我无法手动打开每种方法并在Outlook New Mail中复制内容。 i'm looking for any solution which convert all these txt files to Outlook.MailItem. 我正在寻找将所有这些txt文件转换为Outlook.MailItem的解决方案。 I do appreciate any help. 我非常感谢您的帮助。 thank you 谢谢

What are these files? 这些文件是什么? MIME messages? MIME邮件? In that case you can either explicitly parse them and create new Outlook messages, or you can use Redemption to import them into Outlook. 在这种情况下,您可以显式分析它们并创建新的Outlook消息,也可以使用“ 兑换”将它们导入Outlook。

In VB: 在VB中:

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set Inbox = Session.GetDefaultFolder(olFolderInbox)
  set Msg = Inbox.Items.Add("IPM.Note")
  Mg.Sent = true
  Msg.Import "C:\Temp\test", 1024 'olRfc822
  Msg.Save

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM