【问题标题】:How to open Outlook msg files from disk using perl and Win32::OLE如何使用 perl 和 Win32::OLE 从磁盘打开 Outlook msg 文件
【发布时间】:2021-03-25 03:44:56
【问题描述】:

我有一个目录,里面有我想要处理的 Outlook .msg 文件。 处理将是打开文件并保存附件。 我已成功使用 Win32::OLE 处理 Outlook 文件夹中的邮件, 但这些是磁盘上的文件。如何打开磁盘上的 msg 文件并进行处理 使用 perl 和 Win32::OLE?

限制:我工作的环境不允许我在机器上安装任何东西。特别是,我不能添加其他程序或 perl 模块。我坚持使用全新安装的 perl 附带的模块。

这是我尝试过的:

use Win32::OLE;
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");

$File = Win32::GetFullPathName(".") . "\\" . "TestMessage.msg";
$msg  = $OL->Open($File);       ## Result is undefined

解决方案和/或参考将不胜感激。

【问题讨论】:

  • Win32::OLE->LastError() 显示什么有趣的东西吗?
  • @GeorgMavridis - 是的!我得到Win32::OLE(0.1709) error 0x8002000e: "Invalid number of parameters" in METHOD/PROPERTYGET 。我将尝试在Open 上查找文档
  • 有人解决这个问题了吗??
  • @Mohit。不。我尝试按照错误消息进行操作,但从未得到有效的示例。
  • 但我能做到

标签: perl outlook win32ole


【解决方案1】:

不知何故,在互联网上进行了一些研究后,我得到了以下代码,该代码可以从本地目录中的 .msg 文件中提取附件。将 .msg 路径传递给$filename

my $msg = new Email::Outlook::Message $filename;
my $data = $msg->to_email_mime;
my $stripper = Email::MIME::Attachment::Stripper->new($data);
for my $a ($stripper->attachments()) {
    my $file = $a->{filename};
    open my $fh, '>', $file or die $!;
    print $fh $a->{payload};
    close $fh;
    chmod 0644, $file;
}

【讨论】:

  • 感谢您的回答。这看起来对大多数人来说可能有用,但不幸的是,这个解决方案对我不起作用。正如我在问题的 Restriction 部分所说,我无法在我的工作环境中安装额外的 perl 模块。我有 Email 模块,但没有 Email::Outlook 。
  • 抱歉,当我们有新模块可用时,与旧模块绑定是一种非常糟糕的情况。
猜你喜欢
  • 2013-10-23
  • 1970-01-01
  • 2016-11-19
  • 1970-01-01
  • 2011-09-07
  • 1970-01-01
  • 1970-01-01
  • 2015-09-03
相关资源
最近更新 更多