我正在使用Outllok Interop将电子邮件从一个文件夹移动到另一个文件夹(在获取所有附件之后,但这有效)但它不会复制所有电子邮件.我已经尝试过等待,但它没有效果.首先它会移动6,然后移
相关代码如下:
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);
}
}
}
每次循环移动时,索引都会重置,因此您永远不会超过一半的项目. 使用从olItems.Count到1的While循环或倒计时.
