I have a directory full of Outlook .msg files that I would like to process. The processing will be to open the file and save the attachments. I have used Win32::OLE successfully to process messages in an Outlook folder, but these are files on disk. How can I open a msg file on disk and process it with perl and Win32::OLE?
: I work in an environment where I am not permitted to install anything on the machine.:我在不允许我在机器上安装任何东西的环境中工作。 In particular, I cannot add other programs or perl modules. I am stuck with the modules that come with a fresh installation of perl.
Here is what I tried:
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
use Win32::OLE::Variant;
my $OL = Win32::OLE->GetActiveObject('Outlook.Application') ||
Win32::OLE->new('Outlook.Application', 'Quit');
my $NameSpace = $OL->GetNameSpace("MAPI");
$File = Win32::GetFullPathName(".") . "\\" . "TestMessage.msg";
$msg = $OL->Open($File); ## Result is undefined
Solutions and or references would be appreciated.
I somehow after some research on the Internet got to the below code which does my work to extract attachments from a .msg file present on my local directory.Pass the .msg path to $filename
my $msg = new Email::Outlook::Message $filename;
my $data = $msg->to_email_mime;
my $stripper = Email::MIME::Attachment::Stripper->new($data);
for my $a ($stripper->attachments()) {
my $file = $a->{filename};
open my $fh, '>', $file or die $!;
print $fh $a->{payload};
close $fh;
chmod 0644, $file;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.