【问题标题】:How to check existence of a property in Outlook Interop?如何检查 Outlook 互操作中的属性是否存在?
【发布时间】:2012-08-01 04:46:26
【问题描述】:

我正在尝试在 Outlook 2007 及更高版本中确定电子邮件的发件人。在 Outlook 2010 中,您在 MailItem 对象上有一个 Sender 属性,而在 Outlook 2007 中,您必须像 this question 中提到的那样做不同的事情。

所以现在我需要知道当前版本的 Outlook 是否支持 Sender 属性,如果不支持,请使用其他方法。这样做的原因是我更愿意使用 Sender 属性来与未来版本的 Outlook 兼容,而不是在 Outlook 版本上设置条件。

所以问题是如何确定 Outlook Interop 中是否存在属性?显然,这是一个 COM 对象,我不能在这里使用反射。

【问题讨论】:

  • 您尝试过 try..catch-approach 吗?这在 COM 互操作中经常需要。
  • @Scoregraphic,我已经尝试过这种方法,但它不起作用。 Outlook 只是从中间静默退出,而不进入 catch 块。

标签: com-interop office-interop outlook-addin outlook-2007 outlook-2010


【解决方案1】:

我使用 MailItem.ItemProperties 集合来检查“Sender”属性。下面是代码

Microsoft.Office.Interop.Outlook.MailItem myMail;

//Code to get the mail
....

Microsoft.Office.Interop.Outlook.ItemProperties mailProps = myMail.ItemProperties;

Microsoft.Office.Interop.Outlook.ItemProperty mailProp = mailProps.Item  ("Sender"); //the parameter is case-sensitive

if(mailProp != null)
{
    //get email address using Sender object
    Microsoft.Office.Interop.Outlook.AddressEntry theSender = myMail.Sender;
}
else
{
    //use alternate method for Outlook 2007 
}

【讨论】:

    【解决方案2】:

    可以使用IDispatch::GetIDsOfNames查看属性是否存在

    【讨论】:

    • 您能详细说明一下吗?我不知道我应该如何使用它(到目前为止似乎没有任何注册用户这样做)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    相关资源
    最近更新 更多