我被分配使用perl从ms outlook下载附件,邮件主题为Net file
。由于我是perl的新手,我很困惑如何继续。这是我必须使用的代码
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
my $outlook;
eval {$outlook = Win32::OLE->GetActiveObject('Outlook.Application')};
die "Outlook not installed" if $@;
unless (defined $outlook) {
$outlook = Win32::OLE->new('Outlook.Application','Quit')
or die "Unable to start Outlook";
}
$outlook->{visible} = 0;
my $dir = "F:\\OL\\"; #destination directory
$dir =~ s/\//\\/g;
#get the Inbox folder
my $namespace = $outlook->GetNamespace("MAPI");
有人可以帮助我完成代码的剩余部分。
答案 0 :(得分:1)
您可以从此处获得大量信息:Perl: Win32::OLE and Microsoft Outlook - Iterating through email attachments efficiently或来自http://www.perlmonks.org/?node_id=700307
use strict;
use warnings;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Outlook';
use Win32::OLE::Variant;
my $Folder = $NameSpace->GetDefaultFolder(olFolderInbox);
foreach my $msg (reverse in($Folder->{items}))
print "Subject: ",$msg->{'Subject'},"\n";
next if $msg->{'Subject'} !~ m!Net file!i;
foreach my $atch (reverse in($msg->{Attachments}))
if($atch->{FileName} =~ m/.xls$/i){
if($atch->{FileName} =~ /Name of attachment1/i){
print "found ".$atch->{FileName}."\n";
}
}
}
}
或者您可以使用Mail::Outlook