转发或回复邮件时,获取父邮件项目以阅读标题

问题描述

当邮件被回复或转发时,我想阅读邮件项目标题以查找特定值。如果在标题中找到该值,我们将采取一些措施。下面的代码将捕获Forward事件,但不会为我提供包含所有典型标头数据的父消息。相反,它会基于没有头数据的父项来捕获新消息。这是有道理的,因为尚未发送。

我还尝试对Application.ItemSend事件执行相同的操作,以捕获用户单击发送按钮时的情况。不幸的是,我仍然不知道如何访问父邮件。

我的问题是,当用户单击答复或转发按钮或更好的方法来完全解决此问题时,是否需要使用另一个事件或其他过程来捕获父级?

提前感谢您的帮助!

private void ThisAddIn_Startup(object sender,System.EventArgs e)
        {
            _activeExplorer = Application.Explorers[1];
            _activeExplorer.SelectionChange += _activeExplorer_SelectionChange;
        }

private void _activeExplorer_SelectionChange()
        {
            Selection selection = Application.ActiveExplorer().Selection;
            if (selection != null && selection.Count == 1 && selection[1] is MailItem)
            {
               MailItem selectedMail = selection[1] as MailItem;
               ((Outlook.ItemEvents_10_Event)selectedMail).Forward += mailItem_Forward;
            }
        }

private void mailItem_Forward(object Forward,ref bool Cancel)
        {
            if (Forward != null)
            {
                if (Forward is Outlook.MailItem)
                {
                    Outlook.MailItem mailItem = Forward as Outlook.MailItem;
                    mailItem.Save();
                    String EmailHeader = mailItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");
    
                    // The string is always null because this is a new message,need to access the parent of the forward...how? 
                    if (EmailHeader.Contains("X-Key-Classification") == true)
                    {
                        Debug.WriteLine(EmailHeader);
                    }
                }

            }
        }

解决方法

但是MailItem.Forward事件在特定项目上触发,因此您确实知道该父消息是什么。如果您对多个项目使用相同的回调,则可以为MailItem对象创建一个包装器,并将该对象存储在属性中,并且事件处理程序将在该包装器对象上指定一个方法-这样,您就可以知道引发了哪个项目事件。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...