我正在使用 Outllok Interop 将电子邮件从一个文件夹移动到另一个文件夹(在获取所有附件之后,但它有效)但它并没有复制所有电子邮件。我试过等待,但没有效果。首先它会移动 6,然后是 3,然后是 1。谁能告诉我为什么它不移动它们?
相关代码如下:
Application oOutlook = new Application();
NameSpace oNs = oOutlook.GetNamespace("MAPI");
Recipient oRep = oNs.CreateRecipient("ContentHelp");
MAPIFolder inbox = oNs.GetSharedDefaultFolder(oRep, OlDefaultFolders.olFolderInbox);
MAPIFolder nihSub = inbox.Folders["NIH"];
MAPIFolder nihArchive = inbox.Folders["NIHarchive"];
Items nihItems = nihSub.Items;
MailItem moveMail = null;
//inboxItems = inboxItems.Restrict("[Unread] = false");
int increment = 0;
try
{
foreach (object collectionItem in nihItems)
{
moveMail = collectionItem as MailItem;
if (moveMail != null)
{
Console.WriteLine("Moving {0}", moveMail.Subject.ToString());
string titleSubject = (string)moveMail.Subject;
moveMail.Move(nihArchive);
}
}
}
最佳答案
每次循环移动时索引都会重置,因此您永远不会超过一半的项目。 使用 While 循环或从 olItems.Count 到 1 的倒计时。
关于C# Outlook 不会移动所有电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1577536/