开发者

Get all mails in outlook from a specific folder

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

My folder structure:

Get all mails in outlook from a specific folder

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.GetDefa开发者_如何学编程ultFolder(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)?


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
}


  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");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜