【问题标题】:How to create mail using Mail::Outlook with Outlook 2007如何使用 Mail::Outlook 和 Outlook 2007 创建邮件
【发布时间】:2015-06-25 03:35:15
【问题描述】:

我正在尝试使用Mail::Outlook 创建邮件。我遵循了我认为正确的答案:

Sending email using Perl
Mail::Outlook CPAN

我根据教程创建了一个简单的代码:

use strict;
use warnings;

use Mail::Outlook;
use Data::Dumper;

my $outlook = new Mail::Outlook();
print Dumper($outlook);
print Dumper(Win32::OLE->LastError()); #added in response to comment

my $message = $outlook->create();

$message->To('sample@gmail.com');
$message->Cc('another@gmail.com');

$message->Subject('Testing sending mail from perl');
$message->Body('Hi, This is the body! wahahah!');

$message->save();

1;

我使用的电子邮件是真实的,但出于隐私考虑,我在此处替换了它.. 运行脚本时出现错误:

$VAR1 = undef;
Can't call method "create" on an undefined value at send_mail.pl line 14.  

似乎$outlook 变量在new Mail::Outlook() 期间没有初始化。如果启动新对象失败,模块 Mail::Outlook 将返回 undef。现在,我想知道为什么会这样。我认为这是因为 Outlook 的安全问题,但我不知道如何调整。请perl大师在那里,如果有人有相同的经验或遇到过这种情况,那会有所帮助..

我在 Windows 7 中使用 Microsoft Outlook 2007,并安装了ppm install Mail-Outlook。 我的主要问题是:如何在 Outlook 2007 中使用 Mail::Outlook 创建邮件

更新

我尝试使用print Dumper(Win32::OLE->LastError()); 并打印出这个错误:

$VAR1 = 'Win32::OLE(0.1709) error 0x80080005: "Server execution failed"';

【问题讨论】:

  • 来自新文档:创建一个新的 Outlook 邮件对象。成功时返回对象,失败时返回 undef。要查看最后一个错误,请使用“Win32::OLE->LastError();”。所以打印该命令的输出,看看会弹出什么错误信息
  • 是的,我也试过Wind32::OLE->LastError();,但它似乎没有打印任何东西..
  • 该函数返回值,它不会自行打印任何内容。运行print Dumper(Win32::OLE->LastError())(除非您已经这样做了,在这种情况下,我们无能为力,因为您没有任何错误消息可以指导我们)

标签: perl outlook-2007


【解决方案1】:

按照Tim Tom的指示,稍作搜索,我看到了一篇关于错误Win32::OLE(0.1709) error 0x80080005: "Server execution failed"的文章

COM Process Elevation Mismatching

说outlook应用和perl脚本的访问级别必须一致:

长话短说(令人沮丧),问题是我从提升的 CMD.EXE 窗口运行脚本(“以管理员身份运行”)。当我从非提升的进程(作为普通用户)运行 Outlook 时,似乎存在进程提升不匹配。

在我的情况下也是如此。我以管理员身份运行我的 cmd,而我的 Outlook 运行正常。

MSDN 对此有发言权:

COM 安全知道完整性级别,并且不允许较低完整性的客户端绑定到以较高完整性级别运行的类实例。

在将我的命令行更改为与 Outlook 应用程序相同的高度后,perl 脚本运行良好!

注意: perl 在使用 print Dumper(Win32::OLE->LastError()); 时会崩溃,如果它没有错误的话..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-27
    • 2014-06-21
    • 1970-01-01
    • 2012-11-01
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多