How to read files from Microsoft Outlook
By: Staff
Date: September 13, 2008
Recommended by: readers | 
Level: Advanced |
Here's a very interesting and potentially very useful procedure that import contact information from Outlook's. You can use the procedure in the event to create any application that has a record of your contacts, phone directory type, business partner, etc...
Simply incorporate this process and provide it to your users during installation procedure of your program, to enable them too immediately at the beginning could in your program populate all existing contacts, without the need to manually enter them. Then this information abridged in his own database.
In our case, we have created a new project, for which we have set only two controls; command button (Button) and memory control (Memo). All you need is to enter next procedure within the interpreters of events:
Uses ComObj, Outlook2000;
// or [Outlook8] depending of which Outlook version you use
procedure TForm1.Button1Click(Sender: TObject);
var Outlook : TOutlookApplication;
DefNamespace: NameSpace;
Contacts: MAPIFolder;
Contact: ContactItem;
iCnt: Integer;
begin
Memo1.Clear;
Outlook:=TOutlookApplication.Create(self);
DefNameSpace:=Outlook.GetNamespace(’MAPI’);
// Reading default folder with Contacts
Contacts:=DefNameSpace.GetDefaultFolder(olFolderContacts);
for iCnt:=1 to Contacts.Items.Count do
begin
// Reading separate objects
Contact:=Contacts.Items.Item(iCnt) as ContactItem;
// Reading first and last name of your Contacts
memo1.Lines.Add (Contact.FirstName + ‘ ‘ _
+ Contact.Lastname);
end;
// Removing instance
Outlook.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Memo1.Clear;
end;
|