Using Automation Objects

In this section, we’re going to explore automation objects by building a simple progam that sends a message using Microsoft’s Active Messaging Library . If you don’t have Active Messaging (if you have MAPI, you probably have it) on your system, you can still follow the concepts, which are generally applicable to using automation. Remember, though, that the specific methods, properties, and objects that a server exposes are specific to that server. To learn more about Active Messaging, try the Microsoft MSDN[112] web site at http://msdn.microsoft.com/developer/sdk/ and look for the for Active Messaging Library documentation. The Active Message Library is a complex API that provides complete services for messaging, message stores, providers, transports, and more; but we’re just going to touch on the basics of sending a message here.

The first thing we need to do is to create a Active Messaging session. This happens to be the top-level automation object for our purposes, so we’ll start here with CreateObject :

use OLE;
$ActiveSession = CreateObject OLE "MAPI.Session" || 
        die "CreateObject: $!";

The ProgID for the Active Messaging Session object is MAPI.Session, so that’s the argument that we give to CreateObject. After we have an Active Messaging session, we need to logon. Active Messaging provides a couple of options for doing this. If you don’t supply a valid username/password combination, you’ll get a logon dialog that lets you supply a user and password:

$LogonName ...

Get Learning Perl on Win32 Systems now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.