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

Hello,

Here's what I'm trying to do, and some of the possible solutions I have found. (warning, this may be a long message)

I want to be able to see and extract info from messages going from and to a certain Exchange mailbox. (meaning I don't want to "intercept" messages, just get some info from them and then let them pass) I have delegate access to the mailbox in question. The ultimate goal is to put the info from incoming and outgoing messages into a database, but I can handle that part.

Here are the points I'm struggling with:
  1. I can get to mails using Win32::OLE, but I think it would be easier to use Win32::MAPI. Unfortunately, that module's author seems to have "dropped off the Earth" (not responding to mails, web site gives a 404). Does anyone know where I can get the module? It isn't on CPAN, and I can't find any mirror sites.
  2. I can make my eventual program scan the inbox and sent items folders every X seconds, but that isn't a very clean way of doing what I want to do. Is there a way to "attach" a subroutine to the folders so that it is called when something comes in or something is sent? (This may be solved when I get Win32::MAPI, if that's one of the functions it offers)
  3. I have read in the archives that running a program as a service (even running it as the necessary user) does not load the parts of the registry needed to be able to access an Exchange mailbox. I'll probably try to work around that using Win32::AdminMisc's LogonAsUser() or CreateProcessAsUser(), but if there are some caveats to know about before trying that, I'd like to know about them. (once again, perhaps using Win32::MAPI will eliminate the need to be a certain user to access the mailbox, but I won't know until I get the module)

Once I've gotten those things worked out, I can do the rest. I've just never worked with Exchange before, let alone tried to access it from Perl, and info on this doesn't seem abundant.

Thanks in advance,

Jean-Sebastien Guay

Replies are listed 'Best First'.
Re: Getting mail from Exchange
by Art_XIV (Hermit) on Nov 03, 2003 at 16:52 UTC

    If you are trying to read/manipulate a mailbox and not trying to manipulate Exchange per se, then have a look at Outlook Agents, which are going to be a piece of cake compared to manipulating Exchange itself.

    I've done plenty of agent scripts before, but never w/ Perl. I suspect that doing so wouldn't be a problem since Outlook probably uses Windows Script Host, which handles Activestate Perl very nicely.

    Perl would probably be much nicer than using the scruddy default standards VBScript/JScript. You'll probably still need to keep you OLE module/docs handy, though.

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
      I can't seem to find info on Outlook Agents, would you have a few links to send my way?

      The main reason why I wanted to interface with Exchange directly and not Outlook is that I want the program to work even when I'm not logged in. I think that Outlook needs a real logged in user, and has problems when it's accessed from a service, even if using "run as user".

      Still, thanks for your answer, and if you can give me a few links about Outlook Agents, I would be very grateful.

        Check out slipstick.com, cdolive.com, your exchange server CD docs, and MS Knowledge Base for details. Outlook Agents are somewhat obscure considering what can be done w/them.

        Exchange programming/scripting can be a BIG P.I.A. CDO and MAPI just don't want to play nice w/anybody besides MS languages, and often not even then, at least in my experience. I don't wish to discourage you if this is the direction you want to take, just be forewarned.

        I'm pretty sure that you don't have to be logged into Outlook for the agent(s) to do their thing, but you DO need an instance of Outlook w/ the mailbox you will be manipulating.

        Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
Re: Getting mail from Exchange
by batkins (Chaplain) on Nov 03, 2003 at 20:37 UTC
    Hmm, I may be wrong, but doesn't Exchange use IMAP? If so, you can just use Net::IMAP

    The computer can't tell you the emotional story. It can give you the exact mathematical design, but what's missing is the eyebrows. - Frank Zappa

      That's a great point batkins! Exchange can use IMAP if its configure for it, I believe. I'm voting you up.

      Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
        It can also use POP/SMTP, if it's configured to do it, but it isn't at my site. I have to use it through either Outlook or MAPI....

        :-(

        As I said, I work at a large company who isn't too keen on reconfiguring things for one person who isn't supposed to be doing any programming anyways...