0
我必须创建电子邮件并将它们保存在Outlook(2007)草稿文件夹中。我使用Perl(ActivePerl 5.12.3)和Win32 :: OLE模块。如果Outlook已经打开,它可以正常工作。 Elsif我实例化Outlook,第一封电子邮件保存在收件箱中,剩下的放在草稿文件夹中。以下说明了这个问题。保存在收件箱而不是草稿箱中的新Outlook MailItem
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
my $oMailer;
# Connect to a running version of Outlook
eval { $oMailer =
Win32::OLE->GetActiveObject('Outlook.Application')
};
die "Outlook not installed" if [email protected];
# Start up Outlook if not running
unless(defined $oMailer) {
$oMailer = new Win32::OLE('Outlook.Application', sub {$_[0]->Quit;})
or die "Unable to start an Outlook instance: $!\n";
}
for (my $i=1; $i <5; $i++) {
my $oEmail = $oMailer->CreateItem(0) or
die "Unable to create mail item: $!\n";
$oEmail->{'To'} = '[email protected]';
$oEmail->{'Subject'} = "This is test #$i";
$oEmail->{BodyFormat} = olFormatHTML;
$oEmail->{HTMLBody} = '<html></html>';
$oEmail->save();
}
的M $ dox on MailItem.Save说:
保存在Microsoft Outlook项目到当前文件夹或者,如果这是一个新项目,为项目类型Outlook默认文件夹。
我一直无法找到任何其他在我的搜索努力的报告。任何想法如何让它按照记录工作?
这工作!代码的Perl的版本(未来搜索者)是:my $ namespace = oMailer-> GetNamespace('MAPI'); $ namespace-> Logon(); – EricM 2013-03-12 19:09:40