c#-从特定文件夹中获取Outlook中的所有邮件
作者:互联网
我想从特定的文件夹中获取Outlook中的所有邮件:
我的文件夹结构:
我发现这个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)中获取所有邮件吗?
解决方法:
这应该工作!!!
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
}
标签:email,outlook-addin,c 来源: https://codeday.me/bug/20191208/2092069.html