I am trying to create a mail using Mail::Outlook
. I followed this answers I believe is correct:
Sending email using Perl
Mail::Outlook CPAN
I created a simple code based from the tutorials:
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('[email protected]');
$message->Cc('[email protected]');
$message->Subject('Testing sending mail from perl');
$message->Body('Hi, This is the body! wahahah!');
$message->save();
1;
The emails I used are real but I replaced it here for privacy's sake.. When I run the script, an error appeared:
$VAR1 = undef;
Can't call method "create" on an undefined value at send_mail.pl line 14.
It seems that the variable $outlook
did not initialized during new Mail::Outlook()
. The module Mail::Outlook returns undef
if initiating a new object failed.. Now, I wonder why this happened.. I am thinking it was because of security issues of outlook but I don't know how to tweak that. Please perl masters out there, if anyone has the same experience or have encountered this, it would be helpful..
I am using Microsoft Outlook 2007 in windows 7 and I installed ppm install Mail-Outlook
.
My main question is: How can I create a mail using Mail::Outlook in Outlook 2007
UPDATE
I tried using print Dumper(Win32::OLE->LastError());
and it printed this error:
$VAR1 = 'Win32::OLE(0.1709) error 0x80080005: "Server execution failed"';
After following what Tim Tom has instructed, with a little search, I saw an article about the error
Win32::OLE(0.1709) error 0x80080005: "Server execution failed"
COM Process Elevation Mismatching
It says that the access level of the outlook application and perl script must be the same:
this is the same in my case.. I was running my cmd as Administrator while my outlook was running normally..
MSDN has a say to this:
after changing my command line with the same elevation level as the outlook app, the perl script worked perfectly!
Note: perl crashes while using
print Dumper(Win32::OLE->LastError());
if it has no errors..