Board index » delphi » ExtendedMAPI newbie: using Extended MAPI from within an Outlook COM-Addin

ExtendedMAPI newbie: using Extended MAPI from within an Outlook COM-Addin

First off: are there any Delphi examples on Extended MAPI out there that I
wouldn't have to pay 50$ for?

I've already filled my toolbox with:
- Redemption Objects
- Extended MAPI header translations from Dmitry Streblechenko
- Dmitry's Babelfish and Paul Quall's sample add-ins
- Outlook Spy

I was already getting along fine using the regular Outlook object model or
its Redemption counterparts where necessary but now I've obviously come to
the point where I won't get any further without using Extended MAPI (also
see my earlier post).

I frankly do not even know where to start.

Do I have to use the MAPIInitialize and MAPILogon functions from a COM
Add-in? Am I not already in a logged in context? If so, where can I get my
IMAPISession reference?

The particular problem I'm facing right now is that I need to determine the
user name corresponding to the mailbox of the currently selected folder. I
figured that I would use the StoreID of the currently selected folder (as
could be read from the Outlook object model) to somehow get a IMsgStore
pointer to the mailbox and then read the PR_MAILBOX_OWNER_NAME property.

As I said, my problem is how to get going. Is there a way to query for the
IMsgStore by its StoreID at all or would I have to traverse the entries
returned by IMAPISession.GetMsgStorestable to search for a match myself?

Help? Pointers?

Cheers,

Oliver
---- ------------------
JID: ogie...@jabber.org
ICQ: 18777742
      (http://wwp.icq.com/18777742)

 

Re:ExtendedMAPI newbie: using Extended MAPI from within an Outlook COM-Addin


1. If your code is running in the main Outlook thread, you don't need to
call MAPIInitialize(). If you create your own thread, you do need to call it
if you are using MAPI on that thread.
2. If you are running Outlook 2000 or below, you need to call MAPILogonEx()
to retrieve IMAPISession specifying that you do not want a new session. Note
however that some extensions/addins instantiate a new MAPI session different
from the one used by Outlook, so you could retrieve that session instead. In
Outlook 2002 and up, you can use Namespace.MAPIOBJECT which evaluates to
IMAPISession. Other than that, you can write an Exchange Client Extension
instead (see IExchExtXXX interfaces on MSDN) - works in all versions of
Outlook. This way you will be able to retrieve the session directly from
Outlook.
3. If you already have the store entry id, all you need to do is call
IMAPISession.OpenMsgStore(), no search required.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Quote
"Oliver Giesen" <ogw...@gmx.net> wrote in message

news:3ef7109e$1@newsgroups.borland.com...
Quote
> First off: are there any Delphi examples on Extended MAPI out there that I
> wouldn't have to pay 50$ for?

> I've already filled my toolbox with:
> - Redemption Objects
> - Extended MAPI header translations from Dmitry Streblechenko
> - Dmitry's Babelfish and Paul Quall's sample add-ins
> - Outlook Spy

> I was already getting along fine using the regular Outlook object model or
> its Redemption counterparts where necessary but now I've obviously come to
> the point where I won't get any further without using Extended MAPI (also
> see my earlier post).

> I frankly do not even know where to start.

> Do I have to use the MAPIInitialize and MAPILogon functions from a COM
> Add-in? Am I not already in a logged in context? If so, where can I get my
> IMAPISession reference?

> The particular problem I'm facing right now is that I need to determine
the
> user name corresponding to the mailbox of the currently selected folder. I
> figured that I would use the StoreID of the currently selected folder (as
> could be read from the Outlook object model) to somehow get a IMsgStore
> pointer to the mailbox and then read the PR_MAILBOX_OWNER_NAME property.

> As I said, my problem is how to get going. Is there a way to query for the
> IMsgStore by its StoreID at all or would I have to traverse the entries
> returned by IMAPISession.GetMsgStorestable to search for a match myself?

> Help? Pointers?

> Cheers,

> Oliver
> ---- ------------------
> JID: ogie...@jabber.org
> ICQ: 18777742
>       (http://wwp.icq.com/18777742)

Re:ExtendedMAPI newbie: using Extended MAPI from within an Outlook COM-Addin


Dmitry,

this is exactly the kind of reply I needed! Thanks a lot!

However,

Quote
> 3. If you already have the store entry id, all you need to do is call
> IMAPISession.OpenMsgStore(), no search required.

I'm still having troubles with this step. So far, I retrieved the store id
from the OOM's MAPIFolder.StoreID property, which is a WideString.
IMAPISession.OpenMsgStore however expects a pointer to a binary ENTRYID
structure. I already tried converting the WideString with HrEntryIdFromSz
but this always fails. The docs already said that this method is likely to
become deprecated but I couldn't find any hints at what to use instead.

I'm using Outlook 2000 and Exchange 2000 if that matters.

Cheers,

Oliver
---- ------------------
JID: ogie...@jabber.org
ICQ: 18777742
      (http://wwp.icq.com/18777742)

Re:ExtendedMAPI newbie: using Extended MAPI from within an Outlook COM-Addin


HrEntryIdFromSz expects a PChar, not a WideString.
I use a couple of utility functions that convert strings bin<->hex. Btw,
Delphi strings make for very nice dynamic arrays that you can pass instead
of a pointer to an entry id structure (or any other array):

strBinEntryID:=BinFromHex(MAPIFolder.StoreID);
if S_OK = YourMAPISession.OpenMsgStore(Length(strBinEntryID),
PEntryID(PChar(strBinEntryID)), ...)
...

function BinFromHex(hex : string):string;
var HexStr:string;
    i:integer;
begin
  SetLength(Result,Length(hex) div 2);
  for i:=1 to Length(Result) do begin
    HexStr:='$'+Copy(hex, 2*i-1, 2);
    byte(Result[i]):=StrToInt(HexStr);
  end;
end;

function HexFromBin(lpb : pointer; cb : DWORD):string;
var HexStr:string;
    i:integer;
begin
  SetLength(Result,2*cb);
  for i:=0 to cb-1 do begin
    HexStr:=IntToHex(TByteArray(lpb^)[i], 2);
    Result[2*i+1]:=HexStr[1];
    Result[2*i+2]:=HexStr[2];
  end;
end;

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Quote
"Oliver Giesen" <ogw...@gmx.net> wrote in message

news:3ef81946@newsgroups.borland.com...
Quote
> Dmitry,

> this is exactly the kind of reply I needed! Thanks a lot!

> However,

> > 3. If you already have the store entry id, all you need to do is call
> > IMAPISession.OpenMsgStore(), no search required.

> I'm still having troubles with this step. So far, I retrieved the store id
> from the OOM's MAPIFolder.StoreID property, which is a WideString.
> IMAPISession.OpenMsgStore however expects a pointer to a binary ENTRYID
> structure. I already tried converting the WideString with HrEntryIdFromSz
> but this always fails. The docs already said that this method is likely to
> become deprecated but I couldn't find any hints at what to use instead.

> I'm using Outlook 2000 and Exchange 2000 if that matters.

> Cheers,

> Oliver
> ---- ------------------
> JID: ogie...@jabber.org
> ICQ: 18777742
>       (http://wwp.icq.com/18777742)

Other Threads