一个简单的 if/else 条件就可以完成这项工作。
主要问题是使用 Outlook 的内联响应时。
从版本 13 开始提供。所以我们使用空的 try/catch 来处理它。
Outlook.MailItem Email = null;
Outlook.Inspector actInspector = Outlook.Application.ActiveInspector();
if (actInspector == null)
{
Outlook.Explorer explorer = Outlook.Application.ActiveExplorer();
try
{
Email = explorer.GetType().InvokeMember("ActiveInlineResponse", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public, null, explorer, null) as Outlook.MailItem;
}
finally
{
Marshal.ReleaseComObject(explorer);
}
}
else
{
try
{
Email = actInspector.CurrentItem as Outlook.MailItem;
}
finally
{
if (actInspector != null) Marshal.ReleaseComObject(actInspector);
}
}