Reading Outlook 2000 AddressBook with MAPI.(Active Messaging OLE)

hi there,
 I already have used the MAPI to read Outlook messages and address book,
and it works tell microsoft introduce Outlook 2000...
here is the Code Used to initialize the MAPI session.

MapiSession: Variant;
begin
  MapiSession:=CreateOleObject('MAPI.Session');
...
end;
this Code work good for all Outlook Version prior to Outlook 2000.

do any one know how outlook 2000 deffers from prev version,
and how to deal with this defference.

Thanx in advance.
Dyancer.



LVL 1
dyancerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
Import the type library and use something like:
 
(procedure from test project, use stringlist from listbox for testing). procedure TOutlookAdres.OleGetNamenEnEmail(var stringlist:TStringList); {***********************************************************
pre: outlook is running
discription: get name+email, put them in TStringList
inputs: var TStringList (empty)
returns: var TStringList
***********************************************************}
var
objNS, objAddressLists, objAddresses: Olevariant;
i, k: integer;
s : string;
begin
FOutlook := GetActiveOleObject('Outlook.Application');
objNS:= FOutlook.GetNamespace('MAPI');
objAddressLists:= objNS.AddressLists;
objAddresses:= objAddressLists.Item(1);
k:= objAddresses.AddressEntries.Count;
  for i:=1 to k do
      begin
      s := (objAddresses.AddressEntries.Item(i).Name+', Email:
'+objAddresses.AddressEntries.Item(i).Address);
      stringlist.add(s);
      end;
end;



and another example:


procedure CreateAnOutlookEmail;
  var
    OA , // Outlook Application
    NS , // NameSpace
    MI , // MailItem
    FO , // MapiFolder
    MyUserProperty : variant ;
  begin
 
    OA := CreateOleObject('Outlook.Application') ;
    NS := OA.GetNameSpace('MAPI') ;
    (*  olFolderInbox = 6
        olFolderOutbox = 2
        olFolderDeletedItems = 3
        olFolderSentMail = 5
    *)
    FO := NS.GetDefaultFolder(6) ; // olFolderInbox
 
    IDispatch(MI) := FO.Items.Add('IPM.Note'); // or IPM.Note.MyCustomForm
 
    MI.To := 'user@domain.com' ;
    MI.Subject := 'Outlook EMail from Delphi' ;
    MI.Body := 'Bla bla bla' ;
    //  uncomment the next line if you need to add an attachment     //  MI.Attachments.Add('c:\foo.txt', emptyparam, emptyparam, emptyparam) ;
    MI.Send ; // orMI.Save or MI.whatever
  end;



examples curtesy of Floris Brouwer found on dejanews..

Regards Barry








0
dyancerAuthor Commented:
I'm sorry, I can't accept your answer, but thank you for trying...
As i already mention in the Question title, i'm trying to do this using the
OLE Messaging library...
I mention already that i have a working program for Reading Address book and importing messages from (Outlook,Exchange) including Exchange server which behave defferent when it comes to Public folders,
lately few costomers complain that the program doesn't work for Outlook 2000 and when i installed the Outlook 2000 i found that the program fail to initialize a MAPI.Session in the very start of the program, and i include the line

MapiSession:=CreateOleObject('MAPI.Session');
at this point, when dealing with Outlook 2000 MapiSession is equal to UnAssinged, and in prior version MapiSession have the Ole Object.

and the Question Is, Why this line doesn't Work for Outlook 2000 but work for prior versions , and how can i make it work.

Thanx again.
dyancer.


0
ronit051397Commented:
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

JoeBoothCommented:
Outlook versions prior to 2000 use the CDO API's found in MAPI.DLL.  Outlook 2000 no longer uses MAPI, but rather the CDO library API exclusively, so the MAPI calls (such as MAPI.Session) no longer work.  You will need to start with Outlook.application instead on your CreateOleObject call.  

Unfortunately, the structure of the API is different.  There is a VBAOUTL help file that comes with Outlook 200 that documents the new API structure.

The good news is that if you switch your code to use the CDO calls rather than the MAPI calls, prior version of Outlook work as well.  I've used the CDO specific API with Outlook 97 as well as Outlook 2000.

I have code using the CDO library to read messages and to read address books.  Drop me a line if you'd like me to email you the code.
0
dyancerAuthor Commented:
JoeBooth

Please Send me the code to
zhassan@iname.com
and post your comment as a question so i can give u the points...

Thank you in advance,
dyancer.
0
dyancerAuthor Commented:
Still waiting for JoeBooth...
0
JoeBoothCommented:
Here is code to read the address book(s)
I'll send code to read the messages soon

procedure TForm1.ReadAddrBook;
var
   jj,y      : integer;
   theList   : variant;
   cBook     : string;
   thePerson : variant;
   theRecip  : variant;
   cAddr     : string;
   foutLook  : variant;
begin
  try
    // Create the OLE object from Outlook
    ///////////////////////////////////////
    fOutLook   := CreateOLEObject(OUTLOOK_COM_NAME);
  except
     on e:exception do fOutLook := UnAssigned;
  end;


  if not VarIsEmpty(fOutLook) then
  begin
     theList := fOutLook.GetNameSpace('MAPI');     // Get the name space object

     // Loop through all address books available
     ///////////////////////////////
     for jj := 1 to theList.AddressLists.count do
           begin
              cBook := theList.addressLists.item[jj].name;   // Name of the address book
              // Loop through the addresses in the matching address book
              /////////////////////////////////////////////////////////////
              for y := 1 to theList.AddressLists.item[jj].addressEntries.count do
              begin
                 thePerson := theList.AddressLists.item[jj].addressEntries.item[y];
                 //
                 // Properties available for person
                 //
                 // .name         string  - Display name
                 // .id           string  - MAPI ID
                 // .displayType  integer - type of address entry
                 //                         0 -User,  1 -Distribution List
                 //                         2 -Forum, 3 -Agent
                 //                         4 -Organization
                 // .type         string  - address type (Internet, MacMail, etc.)
                 // .address      string  - e-mail address (see below)
                 /////////////////////////////////////////////////
                 try
                    cAddr := thePerson.Address;   // Sometimes this address is not captured and
                 except                           // and an error gets triggered.  In those cases
                    on e:exception do             // we look for the corresponding recipient object
                       begin
                           theRecip  := fOutLook.session.GetRecipientfromId(theperson.id);
                           cAddr     := theRecip.address;
                           theRecip  := UnAssigned;
                        end;
                  end;
                  ShowMessage(cBook+':'+theperson.name+'/'+cAddr);
                  thePerson := UnAssigned;
              end;
          end;
     theList := UnAssigned;
  end;
end;
//////////////////////////////////////////////////////////////
0
JoeBoothCommented:
Here is code to read messages.  Hope this  and the address book help.

procedure TForm1.ReadMsgs;
var
   fOutLook : variant;
   theList  : variant;
   theSpace : variant;
   themsg   : variant;
   y        : integer;
begin
  try
    // Create the OLE object from Outlook
    ///////////////////////////////////////
    fOutLook   := CreateOLEObject(OUTLOOK_COM_NAME);
  except
     on e:exception do fOutLook := UnAssigned;
  end;


  if not VarIsEmpty(fOutLook) then
  begin
     theSpace := fOutLook.GetNameSpace('MAPI');     // Get the name space object
     //
     // Determine which folder to read
     //
     //  3=Deleted messages
     //  4=Outbook
     //  5=Sent mail
     //  6=Inbox
     //  9=Calendar
     // 10=Contacts
     // 11=Journal
     // 12=Notes
     // 13=Tasks
     // 16=Drafts
     //
     ///////////////////////////////////////////////
     theList   := theSpace.Getdefaultfolder(6).items;
     theMsg    := theList.getfirst;
     while not VarIsEmpty(theMsg) do
     begin
        //
        // Message properties
        //
        // .SenderName          string  - name of sender
        // .Subject             string  - subject line
        // .Body                string  - text of message
        // .CC                  string  - list of carbon copies (separated by ;)
        // .TO                  string  - list of recipients (separated by ;)
        // .BCC                 string  - list of blind carbons (separated by ;)
        // .Unread              boolean - has message been read?
        // .BillingInformation  string  - associated billing info
        //
        // There are a variety of other properties as well, take a look in
        // VBAOUTL9.CHM which comes with Outlook 2000.  Look up MailItem...
        ///////////////////////////////////////////////////
        ShowMessage( theMsg.Sendername+' '+theMsg.Subject );

        // Here is how to get attachments
        ////////////////////////////////////
        for y := 1 to theMsg.attachments.count
        do ShowMessage(theMsg.attachments.item[y].fileName);

        theMsg   := UnAssigned;
        theMsg   := theList.getnext;
     end;

     fOutLook := UnAssigned;
     theList  := UnAssigned;
     theSpace := UnAssigned;
  end;
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LischkeCommented:
finally attached...
0
dyancerAuthor Commented:
JoeBooth

 Thanks alot  for  your answer,
 I'm evaluating it now...
 but in first glance i can tell that i miss the part that deal with folders that was created by the user,

in my old program i do something like this,
 Loop through all folders (recursively get into sub folders also)
  if the folder.type is contacts then read all contacts
  if the folder.type is Mail then read all mail
 
in this case i get even in custom folders.



0
JoeBoothCommented:
While it wasn't clear from your original question that you wanted folders as well, I will send you some code to get folders...
0
dyancerAuthor Commented:
JoeBooth
Thanks alot for your answer,
indeed i already moved to CDO technology and immegrate all my source code as well...
your comment about the  help file - really helped  me. the source was only a start point (* still a very good start point*)

some thing that do annoy me is that after i do start Outlook as ole I get message boxes and such.... is there any way to tell outlook to turn silent...
(*don't show message boxes nor warnings or errors*)
0
JoeBoothCommented:
Which calls are giving you dialog boxes?  Most of the calls that might product a dialog box have boolean options not to display any dialog boxes.
0
dyancerAuthor Commented:
JoeBoth,
It's not calls that show up the dialog box, these boxes pops without me calling them,
like the message box asking if i would like to archive my messages (Auto Archive dialog)
or that outlook check for new email messages and pop up a box for either prompting for password or to warn about error or something....

Is there a work around to tell outlook be SILENT.

thanx.
0
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thank you,
Moondancer
Moderator @ Experts Exchange
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.