Link to home
Start Free TrialLog in
Avatar of dyancer
dyancer

asked on

Help : Reading Outlook Address book with Mapi

hi there,
I need a help on How to Read/import Mapi Address book and/or Mapi messages in delphi3.
to say how to get Outlook address book in my delphi program  notice that i need to use extended mapi.
any component,suggestion,comment are welcomed.

if u need more information either put a comment or contact me by email: niceguy25@geocities.com
Avatar of BlackMan
BlackMan

Are you completly bound to using EMAPI? It would be much easier using Outlook objects...
Do you have MAPI up and running allready? You need to look at the AddressBook method of the MAPI session.
Avatar of dyancer

ASKER

thanx BlackMan for your comment,
I'm not bound to any MAPI implementation, i can use any MAPI implementation that take me to the target "geting the outlook AddressBook",
either it was an EMAPI or Outlook Object "Active Mapi Messaging".
the Only limitation for not using Outlook Object is that i don't have the Header files translated to Delphi.
 
Dyancer.
How about OLE, is that an option?
Avatar of dyancer

ASKER

Nope,
The Whole idea is to read all the Address book seamlessly... to say, without annoying the user with alot of dialogs, just One dialog that i build to hold the information,
and this can't be done "i think"  using OLE.

You can indeed talk OLE to Outlook without the user knowing anything about.. Like this

myOLEApp := CreateOLEObject('Outlook.Application');
myNameSpace := myOLEApp.GetNameSpace('MAPI');
myPublicFolder := myNameSpace.Folders['Public Folders'].Folders;
myAllPublicFolder := myPublicFolder.Item['All PublicFolders'].Folders;
myToDoFolder := myAllPublicFolder.Item['Max Development'];
myTaskFolder := mytoDoFolder.Folders['To Do'];
Avatar of dyancer

ASKER

it seems like it worh a try ...
so, i need more information about this techneque.
do u have any sample code in delphi .. or any other documentation,
(* what type those varialbes in the prev example was *)


thanx.
The variables is of type Variant
As fas as I remember, I have a code example at home, I'll look it up tonight..
Avatar of dyancer

ASKER

please send me any code or explanation.
Sorry for the delay, I've been quite busy..
I've fiddled around with some of my old code to try to read Contacts, but haven't quite succeded yet. As I'm out of town for the next week, I'll post the code here, it might give you a clue... (the problem is the properties on the Contact element)
A good source to find more information about it, is www.microsoft.com/outlookdev. There are some VB examples as far as I remember..

---------------------------------
unit OLu;

interface

uses
 StdCtrls, Classes, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
    Button1: TButton;
    lb: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Const
// OlDefaultFolders
  olFolderDeletedItems = 3;
  olFolderOutbox = 4;
  olFolderSentMail = 5;
  olFolderInbox = 6;
  olFolderCalendar = 9;
  olFolderContacts = 10;
  olFolderJournal = 11;
  olFolderNotes = 12;
  olFolderTasks = 13;

var
  Form1: TForm1;

implementation

Uses
  ComObj;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
  MyFolder,
  MyFolders,
  MyFolderItems,
  MyContact,
  myApp,
  myMapi,
  myContacts      : Variant;
  f,a,
  I      : Integer;
begin
  myApp := CreateOleObject('Outlook.Application');
  myMAPI := myApp.GetNameSpace('MAPI');

    MyFolders := MyMAPI.Folders(1);
    MyFolders := MyFolders.Folders;
    For i := 1 to MyFolders.Count do
    begin
       MyFolder := Mymapi.Folders(i);
       lb.items.Add('Folder ' + MyFolder.Name);
    end;


  MyFolder := myMAPI.GetDefaultFolder(olFolderContacts);
  MyFolderItems := MyFolder.Items;
   a := MyFolderItems.Count;
    For i := 1 to a do
    begin
       MyContact := MyFolder.Items(i);
       lb.items.add(mycontact.EMailAddress);  // <-- Here is the problem
    End;

end;

end.

Hi Dyancer, have you played with the code?
Avatar of dyancer

ASKER

Hello BlackMan,
I Got your Code, in the meanwhile time i wrote a program to Read AddressBook using VB5 and i wondered to see that this code is a translation from the VB.
so, i got the code and correct it to work properly.

procedure something;
var   myMapiSession: Variant;
begin
  myMapiSession:= CreateOleObject('MAPI.Session');
  myMapiSession.Logon;
  ShowMessage(MyMapiSession.Application+' === ' + MyMapiSession.Version);  { this should display 'Ole Messagin 1.0' or 1.1 }
{
 for now you have a seesion and u can further work with this session to
 get address book or any thing else like this
.
MyRecipient:=MyMapiSession.AddressBook; {MyRecipient was declared as a Variant }
.
}
 MyMapiSession.LogOut; { close seesion }
end;

thanx a lot for ur code...

dyancer {hassan}

Do you want me to submit the code as an answer or did you solve the problem without my code?
Avatar of dyancer

ASKER

hi BlackMan,
your code was a good HINT for solving the problem using Delphi.
please Submit your comment as an answer and get the WHOLE points.

thanx
Dyancer {hassan}

ASKER CERTIFIED SOLUTION
Avatar of BlackMan
BlackMan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Blackman:  Is there a way this can work with OutLook Express at all??  Im quite happy to open a new q. for it, but just thought I'ld ask first before hand.

Stu
I guess you could use it OE too, but I've never tried. It ought to work with the exact same code..
No it didnt.  I was expecting it would too.  Maybe Express has a different interface then Outlook??  How would I find out what to call.  There is no TLB that I can find for OE :(

Cheers,

Stu.
Seems like there is no interface for OE?!
I'm sorry, I can't help you.. :-(
Typical of good old MS :)

Thats fine.  Just thought I'd ask while the question was still fresh :)

What part of the world are you from?  That was a very quick response.  Im in Australia, Sydney almost.  11:15pm on 19/2.  Is it just moring for you or something?

Anyway, thanks for getting back to me on this.  Much appreciated!

Stu.
I'm in Aalborg, Denmark and it's 1:15 PM here now... So goodnight to you :-)
Avatar of dyancer

ASKER

Hello there...
if any of you got the answer on how to get the Outlook Express
Address book then please post it here or notify me by email so i
can post a new question so u can get some points...

tell now, i found that Outlook Express does not support "Active messaging".
I tried to use Extended Mapi and for no avail...

thanx in advance.
Dyancer
niceguy25@geocities.com