How to open a .pst file (Microsoft Outlook)

How to open a .pst file (Microsoft Outlook)

i am interested in add/delete/modify Contacts.

i use Microsoft Outlook 2003 and 2007.

any url for learn?


thanks
jamiguelAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
If you look at my original post on DP: http://www.delphipages.com/threads/thread.cfm?ID=45745&G=45624
you'll see how I get the email addresses.
0
 
SteveBayConnect With a Mentor Commented:
Here is an example of reading data using Outlook Automation:
http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/Q_23216275.html
0
 
jamiguelAuthor Commented:
ok, i am reading and testing, this example is a good sample, but it work for Tasks,

i try find for Contacts.

Thanks
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
SteveBayCommented:
The technique is the same.
Just use olFolderContacts and olContactItem instead of olFolderTasks and olTaskItem
0
 
Eddie ShipmanConnect With a Mentor All-around developerCommented:
This code shows how to get the contacts from the Global Address Book,
You would have to test for the values you want to delete and then call the delete method.

procedure TForm1.FormCreate(Sender: TObject);
var
 i: Integer;
 myOlApp: Variant;
 myNameSpace: Variant;
 myFolder: Variant;
 myContactItem: Variant;
begin
 myOlApp := CreateOleObject('Outlook.Application');
 myNameSpace := myOlApp.GetNameSpace('MAPI');
 myFolder := myNameSpace.GetDefaultFolder(olFolderContacts);
 for i := 1 to myFolder.Items.Count do
 begin
   myContactItem := myFolder.Items[i];
   // test here if it is he one you want to delete
   if myContactItem.FullName = 'WhatEver' then
     myContactItem.Delete;
 end;
end;

Open in new window

0
 
Eddie ShipmanAll-around developerCommented:
Adding is the same but you need to fill out a lot of information.
My suggestion would be to take a look at the Outlook2000.pas file in the OCX/Servers directory and see all the information for _ContactItem.

For Adding, you just create a new ContactItem like this:

myContactItem := myFolder.CreateItem(olContactItem);
and then fill out he info and call the Save procedure.

Modify is basically the same code as delete, you just get the contact you want to modify, like in the code above for delete, modify the info like in the Add and call Save.
0
 
jamiguelAuthor Commented:
hi EddieShipman:/MrBaseBall34

i added the Comobj Uses. and to added a Listbox, added a line:
l.Items.add(myContactItem);
and yes filled my listbox...

only get the NAme. of the contact (also i checked to delete a contact and was deleted....)

but how get the rest of the info?

email, company name, work phone, .....  (added a image with other columns)

?


mrbas.jpg
0
 
jamiguelAuthor Commented:
actually i am try learn the OUTLOOK2000.PAS file thanks
0
 
jamiguelAuthor Commented:
too reading this: http://www.scalabium.com/faq/dct0145.htm

thanks
0
 
Eddie ShipmanAll-around developerCommented:
Well, there ARE other properties on myContactItem, see Outlook2000.pas for all the properties (_ContactItem)
0
 
jamiguelAuthor Commented:
2 dudes:

1) this work locally but what happend if the outlook express was connected to a Remote Exchange Server? same way?
2) how to chosse a profiel programatically?

thanks
0
 
Eddie ShipmanAll-around developerCommented:
1. Yes it will work if connected to Exchange Server.
2.  Not sure what you mean. Global Addressbook is avail to all users.
0
 
jamiguelAuthor Commented:
bad word profiel, i mean, profile, in Outlook you can chosse different profiles, right?

thanks
0
 
Eddie ShipmanAll-around developerCommented:
Yes, btu like I said, the global address book is avail to all profiles.
Explain a little further, please.
0
 
jamiguelAuthor Commented:
how to specify the profile name?

in your delphi code?
0
 
Eddie ShipmanAll-around developerCommented:
Let me look it up.
0
 
Eddie ShipmanAll-around developerCommented:
I have not tried this but this shows how to get current profile: (Required CDO)


// Gets the current profile name
var
  oSession: Variant;
begin
  oSession := CreateOleObject('MAPI.Session');
  oSession.Logon('', '', False, False);
  FCurrentProfileName := oSession.Name;
  oSession.Logoff;
end;

Open in new window

0
 
jamiguelAuthor Commented:
ok, now and tomorrow tested the code, and very important if can connect to remote Exchange server.... thanks MrBaseball, pls not forget the Ado question, if can, thanks
0
 
Eddie ShipmanAll-around developerCommented:
I've been butting my head against the wall on that one. All I can ever get OUT of the table is the first 4 chars.
Do you know how they are putting the image into the table using VFP? AppendChunk, perhaps?
0
 
jamiguelAuthor Commented:
hi MrBaseBall and all

i pasted a iamge of my Outlook,in my first .pst (Outlook.pst)have only 1 contact, and the other 5481 (t16may09.pst)contacts, see:

C:\Users\MiguelEA\AppData\Local\Microsoft\Outlook>dir
 Volume in drive C is Local Disk
 Volume Serial Number is C25E-5019

 Directory of C:\Users\MiguelEA\AppData\Local\Microsoft\Outlook

20/05/2009  03:55 p.m.    <DIR>          .
20/05/2009  03:55 p.m.    <DIR>          ..
03/03/2009  11:33 a.m.    <DIR>          Accounts
03/03/2009  11:33 a.m.               810 extend.dat
20/05/2009  05:01 p.m.    15,316,370,432 Outlook.pst
20/05/2009  05:01 p.m.     1,800,029,184 t16may09.pst
               3 File(s) 17,116,400,426 bytes
               3 Dir(s)   2,074,116,096 bytes free

C:\Users\MiguelEA\AppData\Local\Microsoft\Outlook>

when exceute the code at bottom: i get only 1 contact (outlook.pst) how tell to delphi code that try extract of the file t16may09.pst or better rerun all .pst files....

thanks

procedure TForm1.Button2Click(Sender: TObject);
var
 i: Integer;
 myOlApp: Variant;
 myNameSpace: Variant;
 myFolder: Variant;
 myContactItem: Variant;
 x:String;
begin
 myOlApp := CreateOleObject('Outlook.Application'); //uses comobj
 myNameSpace := myOlApp.GetNameSpace('MAPI');
 myFolder := myNameSpace.GetDefaultFolder(olFolderContacts); //uses outlook2000
 for i := 1 to myFolder.Items.Count do
 begin
   Ng.AddRow();
   myContactItem := myFolder.Items[i];
   Ng.cell[0,Ng.rowcount-1].asstring:=myContactItem.FullName;
   if myContactItem.Email1AddressType = 'SMTP' then
   begin
     x:=myContactItem.Email1Address;
     Ng.cell[3,Ng.rowcount-1].asstring:=x;
   end;
 
   // test here if it is he one you want to delete
{   if myContactItem.FullName = 'WhatEver' then
     myContactItem.Delete;}
 end;
end;

Open in new window

outl1.jpg
0
 
Eddie ShipmanAll-around developerCommented:
OK, the code I posted only opens the GLOBAL ADDRESS BOOK. You need to know what
address book you want to open. I will try to figure that one out.
0
 
jamiguelAuthor Commented:
by moment cant, open or choose other profile....

Moderator, need open other question?

thanks
0
 
jamiguelAuthor Commented:
i am working now on open a profile
0
 
Eddie ShipmanAll-around developerCommented:
BTW, if you do something like this it should help you with the profile thing.
Now remember, because i was trying to SEND messages, this prompted me with the security warning. If you need to get rid of that, lookup Outlook Redemption.
I don't know if it will be required to access the address book for a specific profile. I only have one profile defined so I can't really test this but let me know if it works for you.
var
  objOutlook     : Variant;
  objOutlookName : Variant;
  objOutlookMsg  : Variant;
  objOutlookRecip: Variant;
begin
  objOutlook := CreateOleObject('Outlook.Application');
  try
    objOutlookName := objOutlook.GetNameSpace('MAPI');
    objOutlookName.Logoff;
    //                   User   , Password  , ShowDialog
    // if ShowDialog is True, it will show the logon dialog, However...
    // This logs on with default profile and did not show the 
    // dialog like it should
    objOutlookName.Logon('', '', True, True);
    objOutlookMsg := objOutlook.CreateItem(olMailItem);
    objOutlookRecip := objOutlookMsg.Recipients.Add('user@email.com');
    objOutlookRecip.Type := olTo;
    objOutlookMsg.Subject := 'Updating completed successfully!';
    objOutlookMsg.Body := 'Great job. ';
    objOutlookRecip.Resolve;
    objOutlookMsg.Display;
    objOutlookMsg.Send;
  finally
    objOutlookName.Logoff;
    objOutlook := VarNull;
  end;
end;

Open in new window

0
 
jamiguelAuthor Commented:
much thanks i aprecciate your answer.

hi eddie i am accepted the answer, check please:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_24440213.html

and i want integrate: Open a Profile and get the adress book/contact list

by moment, only need get the addres book, not email.

thanks

you are on Irc? wich server wich channel?
thanks
0
 
Eddie ShipmanAll-around developerCommented:
No IRC, sorry...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.