Added:感谢用户@grapkulec,我正在使用
using Microsoft.Exchange.WebServices.Data;
我正在尝试将电子邮件移动到我已在 Outlook 中创建的文件夹(使用 MS Exchange)。到目前为止,我已经能够将电子邮件移动到草稿或其他众所周知的文件夹名称,但没有成功地将其移动到我创建的名为“示例”的文件夹。
foreach (Item email in findResults.Items)
email.Move(WellKnownFolderName.Drafts);
上面的代码有效;但我不想使用众所周知的文件夹。而且,如果我尝试将代码更改为:
email.Move(Folder.(Example));
or
email.Move(Folder.["Example"]);
它不会移动(在这两种情况下都会引发错误)。我在 MSDN、SO 和通用 C# 上找到了大量有关如何将电子邮件移动到文件夹中的示例 - 但是ONLYOutlook“熟知”的文件夹(草稿、垃圾邮件等),这些文件夹不适用于我创建的文件夹。
Solved!
The Move
由于 ID 格式错误,无论多次尝试,命令都失败。显然移动操作不允许使用名称。我曾尝试过DisplayName
作为一个标识符,这就是让我失望的原因。最后我放弃了DisplayName
,这会有帮助。相反,我通过将 ID 存储在变量中来指向 ID(这阻止了烦人的“ID 格式错误”错误),并且移动成功了。
Code:
Folder rootfolder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
rootfolder.Load();
foreach (Folder folder in rootfolder.FindFolders(new FolderView(100)))
{
// Finds the emails in a certain folder, in this case the Junk Email
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.JunkEmail, new ItemView(10));
// This IF limits what folder the program will seek
if (folder.DisplayName == "Example")
{
// Trust me, the ID is a pain if you want to manually copy and paste it. This stores it in a variable
var fid = folder.Id;
Console.WriteLine(fid);
foreach (Item item in findResults.Items)
{
// Load the email, move the email into the id. Note that MOVE needs a valid ID, which is why storing the ID in a variable works easily.
item.Load();
item.Move(fid);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)