Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

read MS Outlook Calendar

by blahblahblah (Priest)
on Jan 05, 2008 at 03:47 UTC ( #660500=sourcecode: print w/ replies, xml ) Need Help??

Category: Win32 Stuff
Author/Contact Info /msg blahblahblah
Description: Last year I finally had to give up my plain-text mail client and start using outlook, and also lost my linux workstation. Transitioning to outlook wasn't as hard as I'd expected -- it has a lot of keyboard shortcuts -- but I missed the unix calendar program's daily mails. I threw together this quick script to email myself a daily calendar preview, and set it up in my task scheduler to run every morning.
# a script to send me a daily outlook calendar summary
# some references:
#  quick calendar example:
#  handle recurring appts, sorting, etc.:
#  create outlook notes:
#  send outlook mail (trickier than I'd assumed so I used SMTP instead

use strict;

BEGIN {$main::TZ = 'US/Eastern';};

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Outlook';
use Win32::OLE::Variant;
use Date::Manip;

my $OL = Win32::OLE->GetActiveObject('Outlook.Application')
    || Win32::OLE->new('Outlook.Application', 'Quit');
my $NameSpace = $OL->GetNameSpace("MAPI");
my $cal = $NameSpace->GetDefaultFolder(olFolderCalendar) or die("error
+ getting cal folder: " . Win32::OLE->LastError());

my $todayDT = ParseDate("today 00:00:00");
my $today = justDate($todayDT);
my $todayRange = qq{[Start] >= '$today' and [Start] < '$today 11:59 pm
my $tomorrow = justDate(Date_NextWorkDay($todayDT, 1));
my $tomorrowRange = qq{[Start] >= '$tomorrow' and [Start] < '$tomorrow
+ 11:59 pm'};

my $body;
for my $range (['TODAY', $todayRange, $today],
               ['TOMORROW', $tomorrowRange, $tomorrow],
    $body .= sprintf("\n%s %s [%s]\n\n", DayOfWeek($range->[2]), $rang
+e->[2], $range->[0]);

    my $appts = $cal->Items() or die("error getting cal appts: " . Win
    $appts->{IncludeRecurrences} = 'True';
    $appts = $appts->Restrict($range->[1]);
    for my $appt (in $appts)
        $body .= sprintf("%s   %s\n",

my $mail = q{From: "Joe" <>
To: "Joe" <>
Subject: calendar for today

$mail .= "\n$body";
print $mail;

print "sending mail...\n";

use Net::SMTP;
my $smtp = Net::SMTP->new('', Debug => 1);


# for outlook date format:
sub justTime
    my (undef, $time, $ampm) = split(/\s/, $_[0], 3);
    $time = substr($time, 0, -3);  # chop off seconds
    $time =~ s{^ (\d) :}{ $1:}x;

    return join(' ', $time, $ampm);

# for datemanip date format:
sub DayOfWeek
    my ($y, $m, $d) = splitDate($_[0]);
    return [qw(Sun Mon Tue Wed Thu Fri Sat)]->[Date_DayOfWeek($m, $d, 
# for datemanip date format:
sub justDate
    join('-', splitDate($_[0]));
# for datemanip date format:
sub splitDate
    return (substr($_[0], 0, 4),
            substr($_[0], 4, 2),
            substr($_[0], 6, 2));

Comment on read MS Outlook Calendar
Download Code

Back to Code Catacombs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://660500]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2015-11-28 05:20 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (737 votes), past polls