2010-09-07 76 views
0

如何在asp.net C#Outllook项目获得

在这里得到Outlook 2007中的当前项目是一些代码,让所有邮件

Microsoft.Office.Interop.Outlook.Application应用= NULL; Microsoft.Office.Interop.Outlook._NameSpace ns = null; Microsoft.Office.Interop.Outlook.MailItem item = null; Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null; Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;

 try 
     { 
     app = new Microsoft.Office.Interop.Outlook.Application(); 
     ns = app.GetNamespace("MAPI"); 
     ns.Logon(null,null,false, false); 

      inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox); 
      //subFolder =inboxFolder.Folders["inbox"]; //inboxFolder.Folders[1]; also works 

      //Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID); 
      //Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString()); 

      for (int i = 1; i <= inboxFolder.Items.Count; i++) 
      { 
       item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[i]; 
       // System.Windows.Forms.MessageBox.Show("Item: {0} {1}", i.ToString()); 
       //Console.WriteLine("Subject: {0}", item.Subject); 
       //Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString()); 
       //Console.WriteLine("Categories: {0}", item.Categories); 
       //Console.WriteLine("Body: {0}", item.Body); 
       //Console.WriteLine("HTMLBody: {0}", item.HTMLBody); 
       // System.Windows.Forms.MessageBox.Show(" Subject: " + item.Subject + " TO: " + item.To + " " + item.Body); 
       System.Windows.Forms.MessageBox.Show(i.ToString()); 
      } 
      System.Windows.Forms.MessageBox.Show(" Subject: " + item.Subject + " TO: " + item.To + " " + item.Body);  
      } 
    catch (Exception ex) 
     { 
     Console.WriteLine(ex.ToString()); 
     } 

回答

0

Explorer对象有一个属性 - 选择其中contaisn在活动explorer.You选择可以检查此属性来确定Outlook中的当前项目的所有物品。

Outlook.Explorer currentExplorer = this.ActiveExplorer(); 
    if (this.ActiveExplorer().Selection.Count > 0){ 
Object selObject = this.ActiveExplorer().Selection[1]; 
     if (selObject is Outlook.MailItem) 
     { 
      Outlook.MailItem mailItem = 
       (selObject as Outlook.MailItem); 
      itemMessage ="The item is an e-mail message." + 
       " The subject is " + mailItem.Subject + "."; 
     } 
} 

This link可能对您有帮助。