On Thu, 21 Dec 2000 18:08:33 +0530,
Raghuram P <[EMAIL PROTECTED]> wrote:
>Hello All
> 
>Can some one of you point me to resource(s) as How to manipulate mails
with
>attachments stored in PST format. I am running Outlook 2000 on a Win2k
Box.
>I have a folder with around 500 mails stored in a pst file and all these
>mails have attachments (txt files) and I need to save all these
attachments
>on to the system for further manipulation. Can I use Win32::OLE ? If yes
can
>someone help me out. 
> 
>Thanks in Advance
>Raghu

Hi Raghu,

The following script will do what you want. It makes two
assumptions that you may need to change:
1) The script processes all mail items that are in your Inbox.
     If your mail is in a different folder, you could move the items to
the
     Inbox before running the script. That would probably be simpler
     than trying to figure out how to reference a user-defined folder.
2) The script puts all the attachments into "C:\Save".

use Win32::OLE qw(in);
use Win32::OLE::Const;

my $olConsts = Win32::OLE::Const->Load("Microsoft Outlook");
my $Outlook = Win32::OLE->GetActiveObject("Outlook.Application") or die;
my $Inbox = $Outlook->GetNamespace("MAPI")
                       ->GetDefaultFolder($olConsts->{olFolderInbox});

foreach my $item (in $Inbox->{Items}) {
   foreach my $attachment (in $item->{Attachments}) {
      $attachment->SaveAsFile("C:\\Save\\$attachment->{Filename}");
   }
}

For future reference, you can find details about the Outlook object
model in the VBA/Outlook help file. Search for "Attachment Object"
for the details on Attachment methods & properties. For a
"birds eye" view of the Outlook Object Model, search for "Microsoft
Outlook Objects".

If you don't have VBA installed on your system, you can find the same
information on the web (You will have to paste together each URL. The
MSDN URLs rapidly get quite long).
URL for Attachment Object -
http://msdn.microsoft.com/library/default.asp?URL=/library/officedev/off2
000/olobjattachment.htm

URL for Outlook Object Model -
http://msdn.microsoft.com/library/default.asp?URL=/library/officedev/off2
000/oltocobjectmodelapplication.htm

For your problem, the following steps could be used to derive a script:
* First we determine the object chain: Application->NameSpace
   ->Folders(Folder)->Items(Item)->Attachments(Attachment).
* Second, we determine the appropriate methods/properties to access
  the object at the end of the chain.
* Third, once we have the Attachment object, we determine the method,
  SaveAsFile, to actually save the attached file.
* Fourth, we translate the VBA syntax to Perl.

HTH,
Jonathan D Johnston
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to