vba 使用 EntryID、StoreID 和/或 PR_ENTRYID 打开 Outlook 邮件项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7438219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:53:31  来源:igfitidea点击:

Open Outlook mail Item using EntryID, StoreID, and / or PR_ENTRYID

vbaoutlookexchange-servermapimailitem

提问by Kyland Holmes

NOTE: I'm using VBA and Office 2007. (I would use C#, but the project parameters don't allow this)

注意:我使用的是 VBA 和 Office 2007。(我会使用 C#,但项目参数不允许这样做)

I'm attempting to find some method in Outlook, or an API, that will allow me to open an Outlook mail item by providing either the Outlook EntryID or the MAPI "PR_ENTRYID" property from an Access Database. I have found many references to said code, but I have never seen anyone actually post a solution. I have attempted in include references to mapi32.dll and OLMAPI32.dll, but I get the following error: "Can't add a reference to the specified file." I'm guessing this is because those dll's are meant for .NET.

我正在尝试在 Outlook 或 API 中找到一些方法,通过提供 Access 数据库中的 Outlook EntryID 或 MAPI“PR_ENTRYID”属性,我可以打开 Outlook 邮件项目。我发现了许多对上述代码的引用,但我从未见过有人真正发布过解决方案。我曾尝试包含对 mapi32.dll 和 OLMAPI32.dll 的引用,但出现以下错误:“无法添加对指定文件的引用。” 我猜这是因为那些 dll 是为 .NET 设计的。

Any help you can give would be greatly appreciated.

您能提供的任何帮助将不胜感激。

回答by Dmitry Streblechenko

Use Namespace.GetItemFromID. Note the second parameter (store id) is optional. You can omit it if the store in question was already touched by Outlook is in the current session. If not, Outlook will raise the "unknown entry id" exception. If the store entry id is specified, Outlook will open it first, and the store provider will have a chance to register its entry ids with the MAPI system.

使用Namespace.GetItemFromID. 请注意,第二个参数(商店 ID)是可选的。如果 Outlook 已经接触到的商店在当前会话中,则可以省略它。如果没有,Outlook 将引发“未知条目 ID”异常。如果指定了商店条目 id,Outlook 将首先打开它,商店提供者将有机会向 MAPI 系统注册其条目 id。

set App = CreateObject("Outlook.Application")
set NS = App.GetNamespace("MAPI")
NS.Logon
set Msg = NS.GetItemFromID(EntryID)
MsgBox Msg.Subject

回答by Berezh

For C#:

对于 C#:

var ns = OutlookApp.GetNamespace("MAPI");
var item = ns.GetItemFromID(entryId) as MailItem;

Where OutlookApp has Microsoft.Office.Interop.Outlook._Application type.

其中 OutlookApp 具有 Microsoft.Office.Interop.Outlook._Application 类型。