【发布时间】:2021-01-21 16:18:50
【问题描述】:
我想在回复或转发邮件时读取邮件标题以查找特定值。如果在标头中找到该值,我们将采取一些措施。下面的代码将捕获 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);
}
}
}
}
【问题讨论】:
标签: c#-4.0 .net-4.0 vsto outlook-addin mailitem