获取 Outlook 中特定文件夹中的所有邮件

发布于 2024-11-01 15:22:43 字数 783 浏览 4 评论 0原文

我想从特定文件夹获取 Outlook 中的所有邮件:

我的文件夹结构:

我的文件夹结构

我发现这个 代码获取outlook收件箱文件夹中的所有邮件(不是图片中的收件箱!):

Outlook.Application oApp;
Outlook._NameSpace oNS;
Outlook.MAPIFolder oFolder;
Outlook._Explorer oExp;

oApp = new Outlook.Application();
oNS = (Outlook._NameSpace)oApp.GetNamespace("MAPI");
oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
oExp = oFolder.GetExplorer(false);
oNS.Logon(Missing.Value, Missing.Value, false, true);

Outlook.Items items = oFolder.Items;
foreach (Outlook.MailItem mail in items)
{
    //do someting
}

有人可以吗告诉我如何从特定文件夹(例如:wolfy-server)获取所有邮件?

I would like to get all mails in outlook from a specific folder:

My folder structure:

My folder structure

I find this Code to get all mails in outlook inbox folder (not the inbox in picture!):

Outlook.Application oApp;
Outlook._NameSpace oNS;
Outlook.MAPIFolder oFolder;
Outlook._Explorer oExp;

oApp = new Outlook.Application();
oNS = (Outlook._NameSpace)oApp.GetNamespace("MAPI");
oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
oExp = oFolder.GetExplorer(false);
oNS.Logon(Missing.Value, Missing.Value, false, true);

Outlook.Items items = oFolder.Items;
foreach (Outlook.MailItem mail in items)
{
    //do someting
}

Can someone tell me how to get all mails from a specific folder (like: wolfy-server)?

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

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

发布评论

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

评论(2

挖鼻大婶 2024-11-08 15:22:43

这应该有效!

MAPIFolder mailsFromThisFolder;

MAPIFolder mainFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

foreach (MAPIFolder folder in mainFolder.Folders)
{
    GetFolders(folder);
}

public void GetFolders(MAPIFolder folder)
{
    if (folder.Folders.Count == 0)
    {
            if (folder.Name == "Folder Name")
            {
                Console.WriteLine(m.FullFolderPath);
                mailsFromThisFolder = folder;
            }
    }
    else
    {
         foreach (MAPIFolder subFolder in folder.Folders)
         {
              GetFolders(subFolder);
         }
    }
}

Outlook.Items items = mailsFromThisFolder.Items;
foreach (Outlook.MailItem mail in items)
{
    //do someting
}

This should work!!!

MAPIFolder mailsFromThisFolder;

MAPIFolder mainFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

foreach (MAPIFolder folder in mainFolder.Folders)
{
    GetFolders(folder);
}

public void GetFolders(MAPIFolder folder)
{
    if (folder.Folders.Count == 0)
    {
            if (folder.Name == "Folder Name")
            {
                Console.WriteLine(m.FullFolderPath);
                mailsFromThisFolder = folder;
            }
    }
    else
    {
         foreach (MAPIFolder subFolder in folder.Folders)
         {
              GetFolders(subFolder);
         }
    }
}

Outlook.Items items = mailsFromThisFolder.Items;
foreach (Outlook.MailItem mail in items)
{
    //do someting
}
你与昨日 2024-11-08 15:22:43
  1. 必须先登录,然后才能执行其他操作。
  2. 使用类似下面的内容

    oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    oSubfolder = oFolder.Folders.Item("wolfy-server");

  1. Logon must come before you do anything else.
  2. Use something like the following

    oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
    oSubfolder = oFolder.Folders.Item("wolfy-server");

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