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

Hi,

I'm trying to get the 'To' property out of an item I'm fetching from a subFolder named qa1 :

... my $mm = $mail->GetNamespace("MAPI"); my $Folder = $mm->Folders("Personal Folders"); my $client_folder = $Folder->Folders("qa1"); my $Item = $client_folder->Items; my $last_email = $Item->GetLast(); if ($last_email->{Class} eq olMail) { print $last_email->{To}; } ...
for some reason - the 'To' property is undefined...(ans that is so for the rest of the mail properties...)

How can I get it to see who sent me the mail ?

jdporter moved code tags

Replies are listed 'Best First'.
Re: Getting message property from outlook mail item
by kwaping (Priest) on Jan 25, 2006 at 16:31 UTC
    What class of object is $mail?
Re: Getting message property from outlook mail item
by ikegami (Patriarch) on Jan 25, 2006 at 17:18 UTC

    You need to read more about the objects you're using. For eaxmple,
    my $Item = $client_folder->Items;
    should be
    foreach my $Item (in $client_folder->Items) {

    in is imported using use Win32::OLE qw( in );

    Update: According to Errto,

    my $Item = $client_folder->Items; my $last_email = $Item->GetLast();

    is functionally correct, but would be more accurate as

    my $Items = $client_folder->Items; my $last_email = $Items->GetLast();

    or simply

    my $last_email = $client_folder->Items->GetLast();
      According to MSDN, GetLast is a method of the Items collection itself so there should be no need to use in. Granted the OP is asking for trouble by calling the Items collection $Item but from what I can see there's no problem in the code.
      I don't understand that bit. How does it all work - the importation bit I mean?

        Replace
        use Win32::OLE;
        with
        use Win32::OLE qw( in );
        and you'll have access to the in function.

Re: Getting message property from outlook mail item
by Errto (Vicar) on Jan 25, 2006 at 17:39 UTC
    The basic outline of your code looks ok to me, but I notice two things. One is that you're using the wrong property name - SenderName is the correct property if you want the name of the sender. The other is that you need to make sure you click Yes on the security warning popup that will appear in Outlook when your code tries to access that information.