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

OS: WinNT 4.0 sp6a & Windows 2000 sp3
Exchange 5.5, Outlook 2000
Perl: Activestate 5.61, 622

I'm trying to access a shared inbox that I have full permissions. I am unable to read the folder. Any help would be much appreciated, thank you.
use Win32::OLE; use Win32::OLE::Variant; #Needed for ReceivedTime constant. $Outlook=Win32::OLE->new('Outlook.Application'); $namespace = $Outlook->GetNameSpace("MAPI"); if ($recipient = $namespace->CreateRecipient("inboxname")) { print "OK\n"; } else { print "$!\n"; } if ($recipient->Resolve) { print "Resolved\n"; } else { print "$!, unable to resolve\n"; } if ($p2 = $namespace->GetSharedDefaultFolder($recipient,6)) { # The code fails here print "OK2\n"; } else { print "$!, Code fails here, does not return an error\n"; }

Replies are listed 'Best First'.
Re: MS Outlook GetSharedDefaultFolder
by NetWallah (Canon) on Sep 04, 2003 at 01:10 UTC
    This MS article may explain the cause of your grief :
    Microsoft Knowledge Base Article - 290064

    OL2002: GetSharedDefaultFolder Method Fails with Some Folder Types

    It states:
    You can use the GetSharedDefaultFolder method with the following folders:
    Calendar
    Tasks
    Inbox
    Contacts
    Notes
    Journal

    These are the folders that are listed in the Outlook user interface when you assign delegate permissions to the folders.

      Thanks for the feedback, but I am trying to read an inbox, which the document says it supports

      Mitch
Re: MS Outlook GetSharedDefaultFolder
by Mr. Muskrat (Canon) on Sep 03, 2003 at 17:42 UTC
    Okay, you're assigning values to variables when you should be checking equality. You need == or eq (depending of the contents of said variables) in place of those = signs.
      The problem seems to be with
      $p2 = $namespace->GetSharedDefaultFolder($recipient, 6)

      using == or eq in the if doesn't help. I am able to successfully resolve the address before this statement by usingprint $recipient->address;

      Mitch
        Wait a minute. You want to assign the value of $namespace->GetSharedDefaultFolder($recipient, 6) to $p2? Then why did you put the assignment inside of an if statement?
Re: MS Outlook GetSharedDefaultFolder
by Mr. Muskrat (Canon) on Sep 03, 2003 at 21:53 UTC

    Okay, I misunderstood what you were trying to accomplish with the if statements initially and I apologize.

    Try moving the variable declarations outside of the if statements.

    #!/perl/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Variant; #Needed for ReceivedTime constant. my $Outlook = Win32::OLE->new('Outlook.Application'); my $namespace = $Outlook->GetNameSpace("MAPI"); my $recipient = $namespace->CreateRecipient("inboxname"); if ($recipient) { print "OK\n"; } else { print "$!\n"; } $recipient->Resolve; # see url if ($recipient->Resolved) { print "Resolved\n"; } else { print "$!, unable to resolve\n"; } my $p2 = $namespace->GetSharedDefaultFolder($recipient,6); # what does + this return? if ($p2) { print "OK2\n"; } else { print "$!, Code fails here, does not return an error\n"; }

    (Untested)

    See also GetSharedDefaultFolder

      I tried that, but $p2 is empty and doesn't return an error. I am able manually open the inbox (via Outlook) so I don't think it's a permission issue. In the past I have been able to read from Public folders, but this is the first time I've tried a shared inbox. I was hoping it would turn out to be a syntax issue, but I think the syntax is OK.

      Mitch

        Perhaps you should use Win32::OLE->LastError() instead of $! for a descriptive OLE error msg.

        $! is for perl errors not OLE, note that Win32::OLE->LastError() is context sensitive like $!.

        It reports the error number in numeric context and an error msg in string context

        I would even consider setting the Warn option to always croak, in normal situations like this

        Win32::OLE->Option(Warn => 3);

        HTH

Re: MS Outlook GetSharedDefaultFolder
by Anonymous Monk on Sep 04, 2003 at 15:25 UTC

    Hi, Mitch

    when you say "inboxname" is that the Name_Of_The_Inbox or your username as recognised by Exchange. You will probably find that it is the later that resolves as a recipient even though the other call to ->resolve may not 'fail'.

      Hi,

      I'm actually using the smtp email address associated with the name, because that seems to be the unique identifier it's using to resolve. When I use the actual mailbox name it doesn't resolve.

      Mitch

        Hi,

        To resolve _my_ mailbox I've always done the following: (this is VBScript so . should be -> etc)

        Const strValidUser = "andermc"; '<- My NT/Exchange username Set objOutlook = CreateObject("Outlook.Application") Set objNS = objOutlook.GetNamespace("MAPI") Set objRecipient = objNS.CreateRecipient(strValidUser) objRecipient.Resolve If (False = objRecipient.Resolved ) Then '<- not return value from abo +ve! 'need to exit nicely

        Now we're resolved we need to get a default folder or whatever.

        Set objInbox = objNS.GetDefaultFolder(olFolderInbox) Set objFolder = objInbox.Folders(a_Folder_UNDER_Inbox) ...

        If the folder you really want isn't in YOUR default mailbox then you should check if that mailbox has a 'NT alias' or 'function ID' associated with it (Properties box from the GAL). Use that alias as the recipient name to get the default folder (olFolderInbox = 6) for that mailbox (Exchange will resolve it if your NT account has sufficient permissions) then use:

        #Create a folder object from a subfolder of Inbox... Set objFolder = objInbox.Folders(strMySubFolder) #Or use the Parent property to move UP the hierarchy

        HTH (and sorry I didn't take the time to convert my old code to Perl!) - Mark