Sra*_*aaz 5 email perl automation ole attachment
我是一个实习生,对此很新...
我的老板每周一收到一封带有两个附件的电子邮件,他必须将其变成维基代码并将其放在我们的内部网站上.由于要转移的信息量,该过程每周一大约需要20分钟.我被要求简化这个过程.
我有代码将解析文件并将其分解为组件,我有代码从他的收件箱中获取所有附件.
我面临的问题是我的脚本从最早的电子邮件开始.这不是一个大问题,但它导致脚本运行的时间比需要的长得多.
#!/usr/bin/perl
use Cwd;
use Win32::OLE qw(in with);
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");
my $Folder = $NameSpace->GetDefaultFolder(olFolderInbox);
my $dir = cwd . "\\";
$dir =~ s/\//\\/g;
my $atch1, $file1, $atch2, $file2;
print ref($Folder->{Items}) . "\n";
foreach my $msg (in $Folder->{Items}){
#print $msg->{CreationTime} . "\n";
foreach my $atch (in $msg->{Attachments}){
if($atch->{FileName} =~ m/.xls$/i){
if($atch->{FileName} =~ /Name of attachment1/i){
$atch1 = $atch;
$file1 = $dir . "file1.xls";
}
if($atch->{FileName} =~ /Name of attachment2/i){
$atch2 = $atch;
$file2 = $dir . "file2.xls";
}
}
}
}
if($atch1 && $atch2){
print $file1 . "\n" . $file2 . "\n";
$atch1->SaveAsFile($file1);
$atch2->SaveAsFile($file2);
}
Run Code Online (Sandbox Code Playgroud)
现在设置它的方式,因为它是最新的,最新的,旨在找到文件,然后只要找到更新的文件(虽然我删除了该功能).实际上我可以找到最新的并停止.
我不知道如何撤销$ Folder - > {Items}.我甚至不明白它是什么.当我做ref($ Folder - > {Items}时,它说它是一个Win32 :: OLE,这对我没什么帮助,因为Win32 :: OLE的文档似乎只是表明它可以是任意数量的东西.
我有什么想法可以先获得更新的电子邮件吗?(撤消$ Folder - > {Items}?Foreach以外的其他东西?将$ folder - > {Items}转移到另一个可以撤销的对象中?只需跳过数千封电子邮件,直到日期在过去2周内?(我不知道)虽然像那个)))
谢谢.
您in从包中导入了子例程 Win32::OLE。这可能是一些可怕的“语法糖”。并深深地除害。Win32::OLE我想它从对象返回某种列表$Folder。所以试试这个:
foreach my $msg (reverse $Folder->{items}->in)\nRun Code Online (Sandbox Code Playgroud)\n\n或者
\n\nforeach my $msg (reverse in($Folder->{items}))\nRun Code Online (Sandbox Code Playgroud)\n\n另外,一定要在每个脚本中使用use strictanduse warnings来确保高质量的代码。如果您确定将使用现代 Perl,您还可以use v5.10享受say函数 \xe2\x80\x93 它的行为类似于print,但会自动在输出中附加换行符。
| 归档时间: |
|
| 查看次数: |
5318 次 |
| 最近记录: |