【问题标题】:New Outlook MailItem saving in Inbox rather than Drafts新的 Outlook MailItem 保存在收件箱而不是草稿中
【发布时间】:2013-03-13 02:38:29
【问题描述】:

我必须创建电子邮件并将它们保存在 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();
}

M$dox on MailItem.Save 说:

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

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

【问题讨论】:

    标签: perl outlook ole


    【解决方案1】:

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

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

    【讨论】:

    • 成功了! Perl 版本的代码(供未来的寻求者使用)是: my $namespace = oMailer->GetNamespace('MAPI'); $namespace->Logon();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 2022-07-15
    • 2012-01-03
    相关资源
    最近更新 更多