#!perl use Win32::OLE; use OLE; my $MAPISession = CreateObject OLE "MAPI.Session" || die; $MAPISession->Logon('servername','password'); #### ####this is where it fails ^ #### $newfile = "./perl_test.txt"; open(BATCH, ">>$newfile") || die "Can't open $newfile : the perl_test.txt file. $!"; ################## sub send_outlook_mail { #use OLE and Outlook to send an email message my $to = ("me\@myemail.com"); my $subject ="DB connection failure"; # my $body = "The connection failed.\n"; # my $cc = shift; # my $cc = ("you\@youremail.com"); #get new Outlook instance my $mail = new Win32::OLE('Outlook.Application') || die "Unable to start Outlook instance: $!"; my $item = $mail->CreateItem(0) || die "Unable to create mail item: $!"; $item->{'To'} = $to; # $item->{'CC'} = $cc; $item->{'Subject'} = $subject; # $item->{'Body'} = $body; #rest of args are file attachments foreach my $attach (@ARGV) { # print STDERR "File attachment: $attach\n"; #make sure the attachment is really there # croak "Missing attachment $attach: $!" if !-e $attach; # my $attachments = $item->Attachments(); # $attachments->Add(); } $item->Send(); my $error = Win32::OLE->LastError(); #carp "Win32::OLE error: $error" if $error; } #sub send_outlook_mail ################ $time = `Time /T`; print BATCH $xx." ".$time; send_outlook_mail(); $MAPISession->Logoff(); # close new .txt file close (BATCH);