use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
use Win32::OLE::Variant;
use Time::Local;
use POSIX;
#open the Outlook program
my $outlook;
eval {
$outlook = Win32::OLE->GetActiveObject('Outlook.Application')
};
if ($@ || !defined($outlook)) {
$outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;}) or die "oops\n";
}
my $namespace = $outlook->GetNameSpace("MAPI") or die "can't open MAPI namespace\n";
my $Folder;
my $subfoldernm = "Calendar";
my $sheetcnt = $namespace->Folders->Count();
foreach (1..$sheetcnt){
$Folder = $namespace->Folders($_)->{Name};
print "\n\t No.". $_ ." Folder Name - >" .$Folder ."<\n";
print "\n\t\tNo.\tItems\tItems";
my $subfldrcnt = $namespace->Folders($Folder)->Folders()->Count or my $dummy = "true";
foreach (1..$subfldrcnt){
my $subfolder = $namespace->Folders($Folder)->Folders($_)->{Name} or die "cant access folder $Folder";
my $itemcnt = $namespace->Folders($Folder)->Folders($subfolder)->Items()->Count or my $empty = "true";
print "\n\t\t$_\t$itemcnt\t$subfolder";
}
}
####
my $cal = new Win32::OLE('Outlook.Application');
$cal->{'Visible'} = 1;
my $item = $cal->CreateItem(0);
$item->{'Subject'} = "perl test";
$item->{'Location'} = "Test Location";
$item->{'Start'} = "04/30/2002 12:00";
$item->{'End'} = "04/30/2002 12:30";
my $selectfolder = $namespace->Folders($Folder)->Folders($subfolder)->Items()->Add($item) or " **** can't add item";
####
#my $mail = new Win32::OLE('Outlook.Application');
#$mail->{'Visible'} = 1;
#my $item = $mail->CreateItem(0);
#$item->{'Subject'} = "This is a test";
#$item->{'To'} = "david.booth\@easynet.co.uk";
#$item->{'Body'} = "Here is the meat of the message";
#$item->Send();
#$mail->Quit();