我正在尝试编写一个加载项,该加载项可以在加载 Outlook MailItem 时对其进行修改(通过预览 Pane 或通过打开它)。这是我到目前为止的代码,但我似乎无法实际访问 MailItem
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, EventArgs e)
{
Application.ItemLoad += ApplicationOnItemLoad;
}
private void ApplicationOnItemLoad(object item)
{
var mail = item as MailItem;
if (mail != null)
{
Console.WriteLine(mail.HTMLBody);
}
}
// Etc...
}
代码到达 Console.WriteLine(mail.HTMLBody);
语句就很好,这意味着将项目转换为 Outlook MailItem 没问题(它最终不会为空)。但是,我无法访问任何 MailItem 成员...它只会引发异常:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in MyOutlookProject.DLL
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
最佳答案
Application.ItemLoad
发生在元素完全装载之前。除了 Class
和 MessageClass
之外,您无法读取 Item
上的任何属性。
来自 MSDN...
This event occurs when the Outlook item begins to load into memory. Data for the item is not yet available, other than the values for the Class and MessageClass properties of the Outlook item, so an error occurs when calling any property other than Class or MessageClass for the Outlook item returned in Item.
要访问预览 Pane 中的 MailItem
,您应该查看 Explorer.Selection
。要访问已打开的 MailItem
(通过检查器) - 利用 Inspectors.NewInspector
.
关于c# - 如何更改在预览 Pane 中显示或打开的 MailItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11476273/