Over the Christmas break, I decided to tackle a small project that may have been a little beyond my perl skills. I wanted a win32 perl process to monitor incoming Outlook email and notify another perl process on a different network machine(linux). With plenty of FAQ searches, googling, etc. I managed to get 90% of what I needed...now I seek the wisdom of the perlmonks. Read on for some background on why I'm trying to do this and a description of the problem...

...many moons ago, my work mail was sent exclusively through a unix based mail server. I worked on a linux machine and used pine, exmh, then netscape mail for awhile. Slowly though, my workgroup and the rest of the company moved to Exchange servers/Outlook mail for all mail/meeting stuff. For awhile I forwarded everything to the unix mail, but eventually I got more and more excel/word/ppt/ attachments , having to log into a windows terminal server session to invoke outlook periodically to check my exchange mail. Now I keep a wts session with outlook running(using rdesktop) up in one of many virtual desktops (fvwm2) So...

My problem though was that when working in one of the other virtual dekstops, I wasn't notified of new outlook mails/reminders. I wanted a little xbiff like widget that notified me of new mail with perhaps even a subject preview. Miricle of Miricles, I noticed that they recently installed activestate perl on the wts machines. So I decided to try and use a win32/ole interface to notify me of incoming mail or reminders and a seperate process would launch a simple tcp server that would handle 2 clients. The win32 process(client1) detects an outlook event, notifies the tcp server, then the server notifies a remote perl/tk app(client2). My problem is that when I attempt to retrieve the mail sender or address property I get an Outlook security prompt:
my $namespace = $outlook->GetNamespace("MAPI"); my $folder = $namespace->GetDefaultFolder(olFolderInbox); my $mailitems = $folder->Items; my $firstmail = $mailitems->GetFirst; my $subject = $firstmail->Subject; my $sendername = $firstmail->SenderName; #Outlook security prompt
I found a description of possible workarounds at this site:
http://www.outlookcode.com/d/sec.htm

-but they all involve either installing a 3rd party app (I'm not allowed to touch the windows registry on these wts machines) or they are beyond my meager skills. Does anyone know a way around this? I can probably live without knowing the sender name on a message pop up, but I figured if anyone knew how do do this in perl, it would be someone reading perlmonks...and tips would be much appreciated.

I'll post the code of the win32 perl script (active state 5.6.1) that monitors outlook and launches a tcp server:
#!/usr/bin/perl use strict; use Win32::Process; use Tk; use Win32::OLE qw(EVENTS); use Win32::OLE::Const 'Microsoft Outlook'; use IO::Socket; use subs qw(dump_calendar Event GetMessage ErrorReport exit_app); require Tk::ROText; my $homelog = "H:/outlook_calendar.dump"; my $ProcessObj; Win32::Process::Create($ProcessObj, 'C:\Perl\bin\perl.exe', 'perl H:\b +in\receiver.pl', 0, DETACHED_PROCESS , ".")|| die ErrorReport(); ######client coonection to above server process my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => '8008', Proto => 'tcp', ); defined $socket or die "ERROR: Can't connect to port 8008\n"; #Get the active outlook process my $outlook = Win32::OLE->GetActiveObject('Outlook.Application') or di +e "Error! $!\n"; #Event handler for newmails/reminders/etc Win32::OLE->WithEvents($outlook,\&Event,"ApplicationEvents_10"); ######################################### #Create a basic window with a text widget my $mw = new MainWindow; my $mw_text = $mw->Scrolled(qw/ROText -scrollbars ose/)->pack; my $mw_entry = $mw->Entry()->pack(qw/-fill x -pady 5/); $mw->bind('<Any-Enter>' => sub { $mw_entry->Tk::focus }); #$mw_entry->bind('<Return>' => [\&broadcast, $socket]); $mw_entry->bind('<Return>' => sub { my $text = $mw_entry->get; $mw_entry->delete(qw/0 end/); print $socket "$text\n"; }); $mw->protocol('WM_DELETE_WINDOW', \&exit_app); MainLoop; ########################################### #Win32::OLE->MessageLoop(); #Don't need it? already in tk mainloop sub broadcast { my ($ent, $sock) = @_; my $text = $ent->get; $ent->delete(qw/0 end/); print $socket $text, "\n"; } sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } sub dump_calendar { my $namespace = $outlook->GetNamespace("MAPI"); my $folder = $namespace->GetDefaultFolder(olFolderCalendar); my $items = $folder->Items; #Format a date string to use for a Start time filter### my ($dsec,$dmin,$dhour,$dmday,$dmon,$dyear,$dwday,$dyday,$disdst) = +localtime(time); my $fixed_year = $dyear - 100; my $fixed_month = $dmon + 1; my $mon = sprintf("%02d", $fixed_month); my $day = sprintf("%02d", $dmday); my $year = sprintf("%02d", $fixed_year); print "DATE: $mon : $day : $year\n "; my $date_string = "$mon/$day/$year"; ####################################################### my $strToday = "[Start] >= '" .$date_string ." 12:00 am' and [Start] + <= '". $date_string . " 11:59 pm'"; $items->Sort("[Start]"); $items->{IncludeRecurrences} = 1; my $appts = $items->Restrict("$strToday"); $appts->Sort("[Start]"); open (HL, ">$homelog") or die "Couldn't open $homelog: $!\n"; my $current_item = $appts->GetFirst; while ($current_item){ #print "Subject = " . $current_item->{Subject} . "\n"; print HL "Subject = " . $current_item->{Subject} . "\n"; print HL "Start = " . $current_item->{Start}->Date . " " . $curre +nt_item->{Start}->Time ."\n"; print HL "Location = " . $current_item->{Location} . "\n"; $current_item = $appts->GetNext; } close (HL); } sub Event { my ($Obj,$Event,@Args) = @_; if ($Event eq "NewMail" ) { &GetMessage; } elsif ($Event eq "Reminder") { my $appt_item = shift @Args; my $start_time = 'N/A'; my $subject = $appt_item->Subject; my $location = $appt_item->Location; if (defined $appt_item->{Start}){ $start_time = $appt_item->{Start}->Time; } print $socket "APPT: $subject Location: $location Start: $start_ +time\n"; } print "EVENT: $Event\n"; #Win32::OLE->QuitMessageLoop(); } sub GetMessage { my $namespace = $outlook->GetNamespace("MAPI"); my $folder = $namespace->GetDefaultFolder(olFolderInbox); my $mailitems = $folder->Items; my $firstmail = $mailitems->GetFirst; my $subject = $firstmail->Subject; #my $sendername = $firstmail->SenderName; #Outlook security prompt my $sendername = 'unknown'; #print "Sender: '$sendername' Subject: '$subject'\n"; print $socket "MAIL: Sender: '$sendername' Subject: '$subject'\n"; } sub exit_app { $ProcessObj->Kill(0); $mw->destroy; }

In reply to win32, Outlook OLE & security prompt.... by elmangaso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.