Solved

How can I get outlook contact information?

Posted on 2006-11-17
4
297 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

22 Experts available now in Live!

Get 1:1 Help Now