Solved

How to open a .pst file (Microsoft Outlook)

Posted on 2009-05-17
26
640 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 50 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
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 250 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 250 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
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.

 
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

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

Suggested Solutions

Title # Comments Views Activity
how to draw animated progressbar in Tvirtualstringtree 5 117
Delphi cmd execution 6 56
Delphi: how to implement a User Shortcut mapper? 1 95
How to debug For loops? 3 46
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

28 Experts available now in Live!

Get 1:1 Help Now