【问题标题】:download attachments from ms outlook using perl使用 perl 从 ms Outlook 下载附件
【发布时间】:2014-02-21 15:00:32
【问题描述】:

我被分配使用 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");

谁能帮我解决剩下的部分代码。

【问题讨论】:

    标签: perl outlook


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多