我正在使用Outllok Interop将电子邮件从一个文件夹移动到另一个文件夹(在获得所有附件之后,但可行),但不会复制所有电子邮件。我试过等待,但没有效果。首先它会移动6,然后是3,然后是1.谁能告诉我为什么不把它们全部移动?C#Outlook并未移动所有电子邮件
相关代码如下:
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);
}
}
}
请注意,这个答案是根据匿名用户对最终代码的请求创建的。这是未经测试的Outlook对象,但应该给出如何完成它的好主意。 – 2010-01-22 15:46:45