【问题标题】:How to get the MailItem belonging to a read receipt (ReportItem) via Outlook automation如何通过 Outlook 自动化获取属于已读回执 (ReportItem) 的 MailItem
【发布时间】:2012-11-02 02:56:04
【问题描述】:
Outlook 将已读回执存储为 ReportItem 对象。
是否可以获得ID 或属于给定已读回执的原始消息的一些详细信息?我查看了 properties of the ReportItem 对象,但我迷路了。
由于已读回执有不同的形式,我不想以编程方式处理回执的正文 - 如果可能的话,我希望从 Outlook 中获取它。
注意:该解决方案至少应适用于 Outlook 2003 到新版本。
【问题讨论】:
标签:
automation
outlook
vsto
outlook-addin
mailitem
【解决方案1】:
看起来ReportItem 和源MailItem 之间的唯一链接是ConversationIndex 和ConversationTopic。这是 Outlook 用来将已读回执消息与相关源 MailItem 链接在一起的内容。你只需要filter by the ConversationTopic 然后use the first 44 chars of the ConversationIndex to identify the original source MailItem。
对话索引示例
来源索引:01CDC1C35624E2A7BD18CF8C439CA73B62A052922657
收据索引:01CDC1C35624E2A7BD18CF8C439CA73B62A0529226570000012862
您可以使用Items.Restrict 将项目减少到特定的 DASL 过滤器
DASL 搜索:
[ConversationTopic] = 'read receipt ConversationTopic here'
定位 ReportItem 的父 MailItem
Outlook.MailItem source = FindReadReceiptSourceMessage(ri);
string entryID = source.EntryID;
// ...
public static Outlook.MailItem FindReadReceiptSourceMessage(Outlook.ReportItem readReceipt)
{
Outlook.Folder inbox = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
string sourceIndex = readReceipt.ConversationIndex.Substring(0, 44);
string topicFilter = string.Format("[ConversationTopic] = '{0}'", readReceipt.ConversationTopic);
Outlook.Items topicItems = inbox.Items.Restrict(topicFilter);
return topicItems.OfType<Outlook.MailItem>().Where(c=>c.ConversationIndex.Equals(sourceIndex)).FirstOrDefault();
}
【解决方案2】:
您的意思是:“您只需按 ConversationTopic 过滤,然后使用 ConversationIndex 的前 44 个字符来识别原始源 MailItem。”
但我认为我们只过滤 ConversationIndex 的前 44 个字符。因为如果有 2 封电子邮件具有相同的 ConversationTopic,那么我们无需使用 ConversationTopic 进行过滤。
【解决方案3】:
在您的项目“myitem”上使用兑换库。在我看来比上面更好
If vs_sender = "" Then 'read receipts
Set objSMail = CreateObject("Redemption.SafeMailItem")
objSMail.item = myitem
vs_sender = objSMail.SenderEmailAddress
vs_recipient = myitem.Recipients(1).Address
Set objSMail = Nothing
End If