Solved

How to open a .pst file (Microsoft Outlook)

Posted on 2009-05-17
26
634 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
actually i am try learn the OUTLOOK2000.PAS file thanks
0
 

Author Comment

by:jamiguel
Comment Utility
too reading this: http://www.scalabium.com/faq/dct0145.htm

thanks
0
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
bad word profiel, i mean, profile, in Outlook you can chosse different profiles, right?

thanks
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 26

Expert Comment

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

Author Comment

by:jamiguel
Comment Utility
how to specify the profile name?

in your delphi code?
0
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
Let me look it up.
0
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
by moment cant, open or choose other profile....

Moderator, need open other question?

thanks
0
 

Author Closing Comment

by:jamiguel
Comment Utility
i am working now on open a profile
0
 
LVL 26

Expert Comment

by:EddieShipman
Comment Utility
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
Comment Utility
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
Comment Utility
No IRC, sorry...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

11 Experts available now in Live!

Get 1:1 Help Now