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

时间:2011-04-14 08:11:58

标签: c# email outlook-addin

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

我的文件夹结构:

My folder structure

我找到这个Code来获取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)吗?

2 个答案:

答案 0 :(得分:2)

这应该有用!!!

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
}

答案 1 :(得分:1)

  1. 登录之前必须先登录。
  2. 使用以下内容

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