Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to open a .pst file (Microsoft Outlook)

Posted on 2009-05-17
26
Medium Priority
?
663 Views
Last Modified: 2012-05-07
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
0
Comment
Question by:jamiguel
  • 12
  • 12
  • 2
26 Comments
 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 200 total points
ID: 24406934
Here is an example of reading data using Outlook Automation:
http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/Q_23216275.html
0
 

Author Comment

by:jamiguel
ID: 24407214
ok, i am reading and testing, this example is a good sample, but it work for Tasks,

i try find for Contacts.

Thanks
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24411284
The technique is the same.
Just use olFolderContacts and olContactItem instead of olFolderTasks and olTaskItem
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 1000 total points
ID: 24413451
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24413508
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
 

Author Comment

by:jamiguel
ID: 24415424
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
 

Author Comment

by:jamiguel
ID: 24415441
actually i am try learn the OUTLOOK2000.PAS file thanks
0
 

Author Comment

by:jamiguel
ID: 24415491
too reading this: http://www.scalabium.com/faq/dct0145.htm

thanks
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24415603
Well, there ARE other properties on myContactItem, see Outlook2000.pas for all the properties (_ContactItem)
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 1000 total points
ID: 24415615
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
 

Author Comment

by:jamiguel
ID: 24417617
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24418069
1. Yes it will work if connected to Exchange Server.
2.  Not sure what you mean. Global Addressbook is avail to all users.
0
 

Author Comment

by:jamiguel
ID: 24418103
bad word profiel, i mean, profile, in Outlook you can chosse different profiles, right?

thanks
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24418294
Yes, btu like I said, the global address book is avail to all profiles.
Explain a little further, please.
0
 

Author Comment

by:jamiguel
ID: 24418471
how to specify the profile name?

in your delphi code?
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24420979
Let me look it up.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24423229
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
 

Author Comment

by:jamiguel
ID: 24423940
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24424727
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
 

Author Comment

by:jamiguel
ID: 24437125
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24437744
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
 

Author Comment

by:jamiguel
ID: 24466740
by moment cant, open or choose other profile....

Moderator, need open other question?

thanks
0
 

Author Closing Comment

by:jamiguel
ID: 31582394
i am working now on open a profile
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24479619
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
 

Author Comment

by:jamiguel
ID: 24479762
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
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24482992
No IRC, sorry...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

963 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