【问题标题】:Is it possible to move Outlook folders using Win32::OLE?是否可以使用 Win32::OLE 移动 Outlook 文件夹?
【发布时间】:2015-03-22 00:59:07
【问题描述】:

我已设法在 Outlook 中添加文件夹,但不知道如何移动它们。我的代码不会抛出任何警告,也不会移动文件夹:

#!/usr/bin/perl
use strict;
use warnings;

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';

# use existing instance if Outlook is already running, or launch a new one
  my $Outlook;
eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')};
die "Outlook not installed" if $@;
unless (defined $Outlook) {
  $Outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;})
    or die "Oops, cannot start Outlook";
}
my $namespace = $Outlook->GetNamespace("MAPI");

#my $Folder = $namespace->Folders("backupadmin")->Folders(
    # "Inbox")->Folders->Add("test");

my $Folder = $namespace->Folders("backupadmin")->Folders(
     "Inbox")->Folders("test")->MoveTo("test1");     

【问题讨论】:

  • Outlook VB 命名空间看起来很冒险;您的目标是重命名文件夹还是重新设置它的父级?如果目标是命名,...->Folders("test")->Name = "test1" 之类的东西可能会起作用(或者使用正确的语法,如setName 等类似的东西)。 Renaming reference
  • 更正确的是my $Folder = $namespace->Folders("backupadmin")->Folders("Inbox")->Folders("test")->{"Name"} = "test1";(再次假设意图是重命名文件夹,而不是重新设置它的父级),或者...->Folders("test")->SetProperty('Name', "test1")
  • 请注意,还有其他 cmets 建议,一旦应用了这样的重命名,也必须刷新才能看到结果。

标签: perl win32ole


【解决方案1】:

如果您使用流行的 Outlook Redemption 库,您可以检索要移动的文件夹的 RDO 文件夹对象,然后以目标 RDO 文件夹作为参数调用 MoveTo 方法。对于一些示例 Perl 代码,您可以参考使用 Win32::OLE 和 Outlook Redemption 来访问 RDO 文件夹对象的 Email::PST::Win32 CPAN 模块。

Outlook 兑换:http://www.dimastr.com/redemption/home.htm

带有 MoveTo 方法的 RDO 文件夹:http://www.dimastr.com/redemption/rdo/rdofolder.htm

电子邮件::PST::Win32: https://metacpan.org/release/Email-PST-Win32

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2015-04-10
    • 1970-01-01
    • 2015-12-21
    • 2019-11-13
    • 1970-01-01
    相关资源
    最近更新 更多