Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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.

Any help you can give would be greatly appreciated.

like image 298
Kyland Holmes Avatar asked Sep 15 '11 22:09

Kyland Holmes


People also ask

Do outlook emails have a unique ID?

Each message has a Message-ID header, and this is what most systems (such as mailing-list archives) will use to reference a specific message. Usually this ID is assigned by the sender's mail app.

What is EntryID in Outlook?

Each Outlook item has a field called EntryID, which is a unique ID field generated by the messaging storage system for use with the MAPI folders that store the item. It's important to note that whenever an item is created in a folder, it is assigned a new EntryID.


2 Answers

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.

set App = CreateObject("Outlook.Application")
set NS = App.GetNamespace("MAPI")
NS.Logon
set Msg = NS.GetItemFromID(EntryID)
MsgBox Msg.Subject
like image 66
Dmitry Streblechenko Avatar answered Sep 23 '22 15:09

Dmitry Streblechenko


For C#:

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

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

like image 34
Berezh Avatar answered Sep 21 '22 15:09

Berezh