Office 2007:以编程方式控制外出助理?

发布于 2024-08-09 23:45:32 字数 190 浏览 6 评论 0 原文

有谁知道如何以编程方式启用/禁用 Outlook 2007 中外出自动回复的实际状态?

已经在 VS 2008 中搜索了对象浏览器并找到了枚举 Microsoft.Office.Interop.Outlook.OlBusyStatus 但我没有找到任何使用它的类或其他任何内容。

任何想法表示赞赏,谢谢和问候

Does anybody know how to programmatically enable/disable the actual state of the out-of-office auto-responder in Outlook 2007?

Already searched the object browser in VS 2008 and found the enumeration Microsoft.Office.Interop.Outlook.OlBusyStatus but i didn't find any class or anything else using this.

Any idea is appreciated, thanks and regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稍尽春風 2024-08-16 23:45:32

更新:使用改编自这篇博客文章的示例代码更新了下面的代码,该代码可以工作在更广泛的 Outlook 安装中效果更好(例如,同时使用 Exchange 和 PST 或访问多个 Exchange 邮箱的安装)。

以下代码适用于 Outlook 2007,用于从外部(到 Outlook)EXE 设置 OOF 状态:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace ns = app.Session;
foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores)
{
    if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox)
    {
        store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF
        break;
    }
}

确保您没有以管理员身份运行该代码,也没有以非管理员身份运行 Outlook,否则您可能会在 Vista 上收到与安全相关的错误。

请注意,它将在 Outlook 中弹出安全对话框,以确保用户同意您访问 Outlook 对象模型。当从外部 EXE 访问 Outlook 对象模型时,这是正常的。

但是,如果您从加载项访问对象模型,则上面的代码并不完全正确:您需要获取对受信任 Outlook 的引用,而不是通过构造函数创建新的 Outlook.Application 对象加载项内部的 .Application 对象,如下所示:

Microsoft.Office.Interop.Outlook.NameSpace ns = this.Application.Session;
foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores)
{
    if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox)
    {
        store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF
        break;
    }
}

顺便说一句,有一个很好的 有关加载项安全性的 MSDN 文章,如果您遇到安全对话框或错误,该文章可能会很有用。

UPDATE: Updated the code below using sample code adapted from this blog post which will work better in a wider variety of Outlook installations (e.g. ones using both Exchange and PST or accessing multiple Exchange mailboxes).

Here's code which worked for me on Outlook 2007, to set the OOF status from an external (to Outlook) EXE:

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace ns = app.Session;
foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores)
{
    if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox)
    {
        store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF
        break;
    }
}

Make sure you're not running that code as Administrator and outlook as non-Administrator-- otherwise you may get a security-related error on Vista.

Note that it will pop up security dialogs inside Outlook to ensure the user is OK with you accessing the Outlook object model. This is normal when outlook object model is accessed from an external EXE.

If, however, you're accessing the object model from an add-in, the code above isn't fully correct: instead of creating a new Outlook.Application object via the constructor, you you need to get a reference to the trusted Outlook.Application object from inside your add-in, like this:

Microsoft.Office.Interop.Outlook.NameSpace ns = this.Application.Session;
foreach (Microsoft.Office.Interop.Outlook.Store store in ns.Stores)
{
    if (store.ExchangeStoreType == Microsoft.Office.Interop.Outlook.OlExchangeStoreType.olPrimaryExchangeMailbox)
    {
        store.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x661D000B", true); // false to turn off OOF
        break;
    }
}

BTW, there's a good MSDN article on security for add-ins, which may be useful if you run into security dialogs or errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文