Solved

How can I get outlook contact information?

Posted on 2006-11-17
4
301 Views
Last Modified: 2010-05-18
I want to get all contct list of M$ outlook~
I need Name, PhoneNumber, E-mail, ...
Exactly, My app compatible with outlook import/export outlook contact list!

0
Comment
Question by:byungho
  • 2
4 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17965625
Couple of previous PAQ's on the same subject came up with these answers. Maybe one will help you.

1) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20508808.html

go to torry.net and in the quick search box type in "address book" and ull get the component called twindowsaddressbook, and a sample too, for delphi 5, it works on my d6, so it should work, and then u open the sample project, and play about with it, i had to play about with it, so it would extract all the contacts from the outlook address book


2) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21437814.html

function TForm1.GetContactsFolder(fpath : string) : OLEVariant;
var
  outlook , objns, tfolder,last : OLEVariant;
  done : boolean;
  cpath : string;
begin
  outlook := CreateOLEObject('Outlook.Application');
  objNS:= Outlook.GetNamespace('MAPI');
  tfolder := objns.GetDefaultFolder('olContacts');
  result := tfolder;
  showmessage(tfolder.name);
end;

procedure TForm1.AddFolders(cfolder : OLEVariant ; tnode : TTreeNode);
var
  cfldr,last : OLEVariant;
  done : boolean;
  ttnode,cnode : TTreeNode;
  i : integer;
begin

  for i := 1 to cfolder.items.Count do
  begin
    cnode := trvwSendTo.Items.AddChild(tnode,cfolder.items(i).fullname);
    cnode.ImageIndex:=0;
    cnode.SelectedIndex:=0;
  end;
  if cfolder.folders.Count > 0 then
  begin
    done := false;
    last := cfolder.folders.getlast;
    cfldr := cfolder.folders.getfirst;
    repeat
      if cfldr.name=last.name then
        done:=true;
      ttnode:=trvwsendto.Items.AddChild(tnode,cfldr.name);
      ttnode.ImageIndex:=1;
      ttnode.SelectedIndex:=1;
      AddFolders(cfldr,ttnode);
      cfldr:=cfolder.folders.getnext;
    until done;
  end;
end;

Procedure TForm1.PopulateTreeView;
var
  outlook, NameSpace, Contacts: OleVariant;
  tnode : TTreenode;
begin
  TrvwSendTo.items.Clear;
  outlook := CreateOLEObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');
  Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
  tnode := trvwSendTo.items.addfirst(nil,'Contacts');
  tnode.ImageIndex:=1;
  tnode.SelectedIndex:=1;
  AddFolders(contacts,tnode);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PopulateTreeView;
end;


3) http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21542066.html
0
 

Author Comment

by:byungho
ID: 17970318
thank you ..

I want to find phone numbers(bussiness, home, office..)
0
 
LVL 9

Accepted Solution

by:
bernani earned 50 total points
ID: 17971084

You can check the code I supplied here: http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21779984.html

with this code

(1 Button + 1 ListView on the Form):

implementation

{$R *.DFM}

uses comobj;

procedure TForm1.Button1Click(Sender: TObject);
const
  olFolderContacts = $0000000A;
var
  outlook, NameSpace, Contacts, Contact: OleVariant;
  i: Integer;
begin
  outlook := CreateOleObject('Outlook.Application');
  NameSpace := outlook.GetNameSpace('MAPI');

  Contacts := NameSpace.GetDefaultFolder(olFolderContacts);
  for i := 1 to Contacts.Items.Count do
  begin
   Contact := Contacts.Items.Item(i);
   {now you can read any property of contact. For example, full name and email address}

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Email1Address + '>';
   end;

  Outlook := UnAssigned;
end;

With this example, all you have to do is to add a line or replace the line

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Email1Address + '>';

and change the item Contact.Email1Address by one of those:

Birthday
Business2TelephoneNumber   <--- this one for example
BusinessAddress
BusinessAddressCity
BusinessAddressCountry
BusinessAddressPostalCode
BusinessAddressPostOfficeBox
BusinessAddressState
BusinessAddressStreet
BusinessFaxNumber  
BusinessHomePage
BusinessTelephoneNumber  <--- this one for example
CompanyAndFullName
CompanyMainTelephoneNumber     <--- this one for example
CompanyName
ComputerNetworkName
Department
Email1Address
Email1AddressType
Email1DisplayName
Email2Address
Email2AddressType
Email2DisplayName
Email3Address
Email3AddressType
Email3DisplayName
FirstName
FTPSite
FullName
FullNameAndCompany
GovernmentIDNumber
Hobby
Home2TelephoneNumber
HomeAddress
HomeAddressCity
HomeAddressCountry
HomeAddressPostalCode
HomeAddressPostOfficeBox
HomeAddressState
HomeAddressStree
HomeFaxNumber
HomeTelephoneNumber          <--- this one for example
Initials
ISDNNumber
JobTitle
Language
LastName
LastNameAndFirstName
MailingAddress
MailingAddressCity
MailingAddressCountry
MailingAddressPostalCode
MailingAddressPostOfficeBox
MailingAddressState
MailingAddressStreet
MiddleName
NickName
OfficeLocation
OrganizationalIDNumber
PersonalHomePage
PrimaryTelephoneNumber
Profession
Suffix
Title
WebPage

sth like

   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.Business2TelephoneNumber + '>';
   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.BusinessTelephoneNumber  + '>';
   ListView1.Items.Add.Caption := Contact.FullName + ' <' + Contact.CompanyMainTelephoneNumber + '>';

____________________________

Hope this help.
0
 

Author Comment

by:byungho
ID: 17971500
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now