I would like to get all mails in outlook from a specific folder:
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.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
}
- Logon must come before you do anything else.
Use something like the following
oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); oSubfolder = oFolder.Folders.Item("wolfy-server");
精彩评论