Retreive Contacts data from Outlook using COMate

Share your advanced PureBasic knowledge/code with the community.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Retreive Contacts data from Outlook using COMate

Post by graves »

Hi,
I solved it in this way:

Code: Select all

#olFolderContacts          = 10
#olFolderSuggestedContacts = 30

XIncludeFile "COMatePLUS.pbi"

Global Outlook.COMateObject, NameSpace.COMateObject, Folder.COMateObject, Items.COMateObject, Contact.COMateObject
Global Command.s, property.s, DIM Propty.s(15) 
Propty(01) = "FullName"
Propty(02) = "CompanyName"
Propty(03) = "Email1Address"
Propty(04) = "PrimaryTelephoneNumber"
Propty(05) = "MobileTelephoneNumber"
Propty(06) = "HomeTelephoneNumber"
Propty(07) = "Home2TelephoneNumber"
Propty(08) = "RadioTelephoneNumber"
Propty(09) = "OtherTelephoneNumber"
Propty(10) = "CompanyMainTelephoneNumber"
Propty(11) = "BusinessTelephoneNumber"
Propty(12) = "Business2TelephoneNumber"
Propty(13) = "AssistantTelephoneNumber"
Propty(14) = "CallbackTelephoneNumber"
Propty(15) = "CarTelephoneNumber"

  Outlook = COMate_CreateObject("Outlook.Application")
  if Outlook
    Command = "GetNamespace(" + Chr(39) + "MAPI" + Chr(39) + ")"
    NameSpace = Outlook\GetObjectProperty(Command)
    if NameSpace
      Command = "GetDefaultFolder(" +#olFolderContacts + ")"
      Folder = NameSpace\GetObjectProperty(Command)
      if Folder
        Items = Folder\GetObjectProperty("Items")
        if Items
          for i=1 to i+1
            Command = "Item("+str(i)+")" 
            Contact = Items\GetObjectProperty(Command)
            if not Contact: break: endif
            for p=1 to 15
              property = ""
              property = Contact\GetStringProperty(Propty(p))
              if len(trim(proper)) 
                (your stuff...)
              endif
            next
          next
          if Contact  : Contact\Release()  : endif
          if Items    : Items\Release()    : endif
          if Folder   : Folder\Release()   : endif
          if NameSpace: NameSpace\Release(): endif
          if Outlook  : Outlook\Release()  : endif
        endif
      endif
    endif
  endif
I've used only 15 properties but, of course, there are many more:

Code: Select all

Address                       DownloadState             ItemProperties               OutlookInternalVersion
Account                       Email1Address             JobTitle                     OutlookVersion
Actions                       Email1AddressType         Journal                      PagerNumber
Anniversary                   Email1DisplayName         Language                     Parent
AssistantName                 Email1EntryID             LastFirstAndSuffix           PersonalHomePage
AssistantTelephoneNumber      Email2Address             LastFirstNoSpace             PrimaryTelephoneNumber
Attachments                   Email2AddressType         LastFirstNoSpaceAndSuffix    Profession
AutoResolvedWinner            Email2DisplayName         LastFirstNoSpaceCompany      PropertyAccessor
BillingInformation            Email2EntryID             LastFirstSpaceOnly           RadioTelephoneNumber
Birthday                      Email3Address             LastFirstSpaceOnlyCompany    ReferredBy
Body                          Email3AddressType         LastModificationTime         ReminderOverrideDefault
Business2TelephoneNumber      Email3DisplayName         LastName                     ReminderPlaySound
BusinessAddress               Email3EntryID             LastNameAndFirstName         ReminderSet
BusinessAddressCity           EntryID                   Links                        ReminderSoundFile
BusinessAddressCountry        FileAs                    MailingAddress               ReminderTime
BusinessAddressPostalCode     FirstName                 MailingAddressCity           RTFBody
BusinessAddressPostOfficeBox  FormDescription           MailingAddressCountry        Saved
BusinessAddressState          FTPSite                   MailingAddressPostalCode     SelectedMailingAddress
BusinessAddressStreet         FullName                  MailingAddressPostOfficeBox  Sensitivity
BusinessCardLayoutXml         FullNameAndCompany        MailingAddressState          Size
BusinessCardType              Gender                    MailingAddressStreet         Spouse
BusinessFaxNumber             GetInspector              ManagerName                  Subject
BusinessHomePage              GovernmentIDNumber        MarkForDownload              Suffix
BusinessTelephoneNumber       HasPicture                MessageClass                 TaskCompletedDate
CallbackTelephoneNumber       Hobby                     MiddleName                   TaskDueDate
CarTelephoneNumber            Home2TelephoneNumber      Mileage                      TaskStartDate
Categories                    HomeAddress               MobileTelephoneNumber        TaskSubject
Children                      HomeAddressCity           NetMeetingAlias              TelexNumber
Companies                     HomeAddressCountry        NetMeetingServer             Title
CompanyAndFullName            HomeAddressPostalCode     NickName                     ToDoTaskOrdinal
CompanyLastFirstNoSpace       HomeAddressPostOfficeBox  NoAging                      TTYTDDTelephoneNumber
CompanyLastFirstSpaceOnly     HomeAddressState          OfficeLocation               UnRead
CompanyMainTelephoneNumber    HomeAddressStreet         OrganizationalIDNumber       User1
CompanyName                   HomeFaxNumber             OtherAddress                 User2
ComputerNetworkName           HomeTelephoneNumber       OtherAddressCity             User3
Conflicts                     IMAddress                 OtherAddressCountry          User4
ConversationID                Importance                OtherAddressPostalCode       UserProperties
ConversationIndex             Initials                  OtherAddressPostOfficeBox    WebPage
ConversationTopic             InternetFreeBusyAddress   OtherAddressState            YomiCompanyName
CreationTime                  IsConflict                OtherAddressStreet           YomiFirstName
CustomerID                    ISDNNumber                OtherFaxNumber               YomiLastName
Department                    IsMarkedAsTask            OtherTelephoneNumber         
dige
Addict
Addict
Posts: 1409
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: Retreive Contacts data from Outlook using COMate

Post by dige »

Well done! Thank you for sharing. :D
"Daddy, I'll run faster, then it is not so far..."
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Retreive Contacts data from Outlook using COMate

Post by Joris »

Just trying to run the COMatePLUS.pbi, I get an error at this line :
excep\pfnDeferredFillIn(excep)
[10:39:08] [COMPILER] Line 619: Garbage at the end of the line.
I'm a noob on this and just try to explore what this COMatePLUS does.

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Retreive Contacts data from Outlook using COMate

Post by Kwai chang caine »

Works fine
Thanks for sharing this usefull code 8)
ImageThe happiness is a road...
Not a destination
Post Reply