我发现此代码从指定的收件箱加载所有未读邮件,然后将所有附件保存到本地路径。
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = app.GetNamespace("MAPI");
string recipientName = "user@techcompany.com";
Outlook.Recipient recip = ns.CreateRecipient(recipientName);
recip.Resolve();
Outlook.MAPIFolder inboxFolder = ns.GetSharedDefaultFolder(recip, Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items inBoxItems = inboxFolder.Items;
Outlook.MailItem newEmail = null;
inBoxItems = inBoxItems.Restrict("[Unread] = true");
try
{
foreach (object collectionItem in inBoxItems)
{
newEmail = collectionItem as Outlook.MailItem;
if (newEmail != null)
{
if (newEmail.Attachments.Count > 0)
{
for (int j = 1; j <= newEmail.Attachments.Count; j++)
{
newEmail.Attachments[j].SaveAsFile(@"C:\GetAttachments\" + newEmail.Attachments[j].FileName);
}
}
}
}
}
我需要更改限制(此行:“inBoxItems = inBoxItems.Restrict(”[Unread] = true“);”)仅选择尚未标记为已完成的消息,基本上是未标记的消息。
我试过了:
inBoxItems = inBoxItems.Restrict("[IsMarkedAsTask] = true");
没用。我需要一个有效的限制。我搜索了有效限制列表,但找不到它们。
答案 0 :(得分:0)
inBoxItems = inBoxItems.Restrict("[Complete] = true");