gpt4 book ai didi

outlook - VSTO:在 Outlook 规则移动邮件之前使用 newmailex 处理邮件

转载 作者:行者123 更新时间:2023-12-04 07:13:51 33 4
gpt4 key购买 nike

我正在为 Outlook 2007 创建一个插件,它在收到邮件时读取邮件项目,然后将其重写。该插件运行良好,并为没有将它们移动到另一个文件夹的 Outlook 规则的项目重写邮件。如果有规则,大约 50% 的时间仍然可以。另外 50% 的时间,规则在我的插件完成之前移动邮件项目。我收到以下错误:

"The operation cannot be performed because the object has been deleted."



我正在使用 NewMailEx 事件来调用我的重写函数:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Application.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(olApp_NewMail);
}

在 Outlook 2007 中,NewMailEx 为邮件提供了一个 entryID。此 entryID 最初用于确定要使用的邮件对象:
Outlook.NameSpace outlookNS = this.Application.GetNamespace("MAPI");
Outlook.MAPIFolder mFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.MailItem mail;
try
{
mail = (Outlook.MailItem)outlookNS.GetItemFromID(entryIDCollection, Type.Missing);
}
catch (Exception e) { Debug.WriteLine("exception with non-mail item " + entryIDCollection + ": " + e.ToString()); return; }

我想我可以使用这个 entryID(上面的代码有效),并遍历我的所有文件夹(在交换中以及在我的计算机上)寻找相同的邮件 ID。当我最终迭代到邮件所在的位置时,移动邮件的 EntryID 与 entryIDCollection 非常不同。

也许我会以错误的方式解决这个问题。有谁知道如何阻止事件传播直到我完成,或者如何追踪移动的电子邮件?

这是我用于遍历文件夹的代码,以防有人好奇:
        try
{
mail.Subject = new_subj;
mail.Body = "";
mail.HTMLBody = text;
mail.ClearConversationIndex();
mail.Save();
}
catch (Exception ex)
{
//It wasn't caught in time, so we need to find the mail:
ArrayList unreadFolders = new ArrayList();
foreach (Outlook.Folder f in outlookNS.Folders) unreadFolders.Add(f);

while (unreadFolders.Count > 0)
{
Outlook.Folder currentFolder = unreadFolders[0] as Outlook.Folder;
Debug.WriteLine("reading folder: " + currentFolder.Name);
unreadFolders.RemoveAt(0);


foreach (Outlook.Folder f in currentFolder.Folders) unreadFolders.Add(f);

try
{
Outlook.Items items = currentFolder.Items.Restrict("[UnRead] = true");
for (int itemNum = 1; itemNum <= items.Count; itemNum++)
{
if (!(items[itemNum] is Outlook.MailItem)) continue;
Outlook.MailItem m = items[itemNum];
if (m.EntryID == entryIDCollection)
{
m.Subject = new_subj;
m.Body = "";
m.HTMLBody = text;

m.ClearConversationIndex();
m.Save();
return;
}

}
}
catch (Exception exc) { }
}

}

最佳答案

未经测试的想法:如果您可靠地获取 NewMailEx 事件,请使用用户属性或使用 GUID 的里程标记邮件,然后使用搜索。

这可能不起作用,因为您可能无法在规则移动邮件之前进入。

正如您所计算出的,当项目移动时,EntryId 会发生变化。

其他方式您需要查看 MAPI Prop 以获得 PR_SEARCH_KEY,当邮件四处移动时,该 PR_SEARCH_KEY 会发生变化。

关于outlook - VSTO:在 Outlook 规则移动邮件之前使用 newmailex 处理邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301999/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com