【发布时间】: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