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. 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). I test different tips to cast txt files to Outlook.MailItem but none of them work.for example:
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. (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. i'm looking for any solution which convert all these txt files to Outlook.MailItem. I do appreciate any help. thank you