0

我必须创建电子邮件并将它们保存在 Outlook (2007) 草稿文件夹中。我正在使用 Perl (ActivePerl 5.12.3) 和 Win32::OLE 模块。如果 Outlook 已打开,则它可以正常工作。Elsif 我实例化 Outlook,第一封电子邮件保存在收件箱中,其余的保存在草稿文件夹中。下面演示了这个问题。

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 $@;

# 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'} = 'me@domain.info';
  $oEmail->{'Subject'} = "This is test #$i";
  $oEmail->{BodyFormat} = olFormatHTML;
  $oEmail->{HTMLBody}   = '<html></html>';

  $oEmail->save();
}

MailItem.Save 上的 M$ dox说:

将 Microsoft Outlook 项目保存到当前文件夹,或者,如果这是一个新项目,则保存到项目类型的 Outlook 默认文件夹。

在我的谷歌搜索工作中,我无法找到任何其他关于此的报告。知道如何让它按记录工作吗?

4

1 回答 1

0

这表明您从未登录到 MAPI 会话。

创建 Outlook.Application 对象的实例后,立即检索命名空间对象 (Application.GetNamespace("MAPI"),然后调用 Namespace.Logon

于 2013-03-12T18:38:29.790 回答