DeliriumNZ has asked for the wisdom of the Perl Monks concerning the following question:

Hi I am stuck, I have a gui interface that im setting up to send an automated email, from someone elses email address. I have the rights to send from the email address but when I go to run it it comes up with "Win32::OLE<0.1709> error 0x8002000e: Invalid number of parameters in PROPERTYPUT From at F:\Escalation.pl line 177 Here is the code
use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Variant; use Win32::OLE::Const 'Microsoft Outlook'; my $Outlook = Win32::OLE->GetActiveObject ('Outlook.Application') || Win32::OLE->new('Outlook.Application'); my $Outlook = new Win32::OLE('Outlook.Application'); # Create Mail Item my $item = $Outlook->CreateItem(0); # 0 = mail item. unless ($item) { die "Outlook is not running, cannot send mail.\n"; } $item->{'Subject'} = $mail_props{'subject'} || '[No Subject]'; $item->{'To'} = join (";", split(/[ ,;]+/, $mail_props{'to'})); $item->{'Body'} = $mail_props{'body'} || "\r\n"; $item->{'From'} = $mail_props{'to'}; # 2=high, 1=normal, 0=low $item->{'Importance'} = 1; # Send the Email $item->Send();
If you could help me that would be greatly appreciated.

Replies are listed 'Best First'.
Re: Sending mail in outlook
by Gangabass (Vicar) on Sep 15, 2009 at 02:06 UTC

    Your code works for me. Except i have added :

    use strict; use warnings;

    And i have also commented:

    my $Outlook = new Win32::OLE('Outlook.Application');

    because you have already defined it.

    What Outlook version you trying?

Re: Sending mail in outlook
by Bloodnok (Vicar) on Sep 14, 2009 at 22:34 UTC
    I'm no expert on M$ (avoiding like the plague if at all possible), however I'd suggest that the result of the statement:
    my $item = $Outlook->CreateItem(0); # 0 = mail item.
    is an object, not a hash ... as you are attempting to update. Maybe something along the lines of (untested as I don't have a Windoze box)
    $item->Subject($mail_props{'subject'} || '[No Subject]');
    . instead of
    $item->{'Subject'} = $mail_props{'subject'} || '[No Subject]';
    Just a thought ...

    A user level that continues to overstate my experience :-))
      Tried that but comes up with the same error message. The line that it seems to have trouble with is $item->{'From'} = $mail_props{'to'};
        Have you tried the object browser to inspect the prototype for the method ?

        AFAIR, it (the object browser) is one of the 'tools' available when Excel is running...

        A user level that continues to overstate my experience :-))