展望项目获得

发布于 2024-09-17 11:56:18 字数 2048 浏览 4 评论 0原文

如何在 asp.net c# 中获取 Outlook 2007 的当前项目

这里是一些获取所有邮件的代码

Microsoft.Office.Interop.Outlook.Application app = null; Microsoft.Office.Interop.Outlook._NameSpace ns = null; Microsoft.Office.Interop.Outlook.MailItem 项目 = null; Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null; Microsoft.Office.Interop.Outlook.MAPIFolder 子文件夹 = 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());
      }

how to get current item of outlook 2007 in asp.net c#

here is some code which get all mails

Microsoft.Office.Interop.Outlook.Application app = 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());
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静若繁花 2024-09-24 11:56:22

Explorer 对象有一个属性 - Selection,其中包含活动资源管理器中选定的所有项目。您可以检查此属性以确定 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 + ".";
        }
}

此链接可能会对您有所帮助。

Explorer object has a property - Selection which contaisn all the items selected in the active explorer.You can check this property to determine the current item in 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 might help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文