Hi to all,

With the request of Sir Steve Gross, I'm posting here the script both for
the one that creates and send mail and the one that opens Outlook and and
thereby automates my sending of log files.

for the one that creates and send mail:

#! c:\perl\bin\perl

use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Outlook';
$|++;
$Win32::OLE::Warn = 2;

print "\n*** Automailer of Logs ***\n\n"; 
print "Opening Outlook Application...\n\n";
$OL = Win32::OLE->GetActiveObject('Outlook.Application')
       || Win32::OLE->new('Outlook.Application', 'Quit');
print "Creating MAPI session...\n\n";
$NameSpace = $OL->GetNameSpace("MAPI");
print "Logging to Outlook...\n\n";
$NameSpace->Logon("profile_name","profile_password","False","True");
print "Creating new message...\n\n";
$MailItem = $OL->CreateItem(olMailItem);
die "Unable to create mail item: $!" if !defined $MailItem;

$to="recipient_to";
$cc="recipient_cc";
$subject="Logs $date_prev";
$body="Sir, attached are the logs for yesterday.\n\nfor your perusal.";
$body.="\n\nregards.\n\nRodel D. Bautista\n\n\n";
print "Adding recipient...\n\n";
$recp_to=$MailItem->Recipients->Add($to);
$recp_to->{'Type'} = 1;
$recp_to->Resolve(); 
$recp_cc=$MailItem->Recipients->Add($cc);
$recp_cc->{'Type'} = 2;
$recp_cc->Resolve(); 
print "Adding subject...\n\n";
$MailItem->{'Subject'} = $subject;
print "Adding body text...\n\n";
$MailItem->{'Body'} = $body;
print "Adding attachments...\n\n";
@attachments=('some_attachments_file');
foreach $attach (@attachments) {
  die "Missing attachment $attach: $!" if !-e $attach;
  $attachments = $MailItem->Attachments->Add($attach);
  }
print "Sending message...\n\n";
$MailItem->Send();
print "Quitting Outlook...\n";

for opening the outlook application:

#! c:\perl\bin\perl

use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow
GetForegroundWindow SendKeys PushButton);

$Win32::GuiTest::debug = 0;

my @windows = FindWindowLike(0, "^Choose Profile",);
for (@windows) {
  print "$_>\t'", GetWindowText($_), "'\n";
  SetForegroundWindow($_);
  PushButton "OK";
  }
sleep 3;  
my @windows1 = FindWindowLike(0, "^Enter Password",);
for (@windows1) {
  print "$_>\t'", GetWindowText($_), "'\n";
  SetForegroundWindow($_);
  SendKeys("some_password{ENTER}");
  #PushButton "OK";
  }

Pls. take note to schedule the opening of outlook first, then run the
mailing script in the "Scheduled Tasks" utility of windows.

I hope this can help other perl users too.

regards.

Rodel D. Bautista

> -----Original Message-----
> From: Steve Gross [SMTP:[EMAIL PROTECTED]
> Sent: Friday, June 20, 2003 9:37 PM
> To:   'Bautista, Rodel D.(Digitel-GSM)'
> Subject:      RE: Using Outlook in Win32::OLE
> 
> Would it be possible to get a copy of your script? 
> Thanks, 
> Steve 
> 
> _________________________________________________ 
> Stephan Gross                      Tel:    973-586-8722 ext. 249 
> IT Manager                          Fax:   973-586-0450 
> Fette America, Inc. 
> 
> 
> > -----Original Message----- 
> > From: Bautista, Rodel D.(Digitel-GSM) 
> > [ <mailto:[EMAIL PROTECTED]>] 
> > Sent: Friday, June 20, 2003 5:10 AM 
> > To: Roy Sprague; PERL-WIN32-USERS; PERL-WIN32-USERS-A; 
> > perl-win32-users-admin 
> > Subject: RE: Using Outlook in Win32::OLE 
> > 
> > 
> > Hi to All, 
> > 
> > This is to thank you all for your help and assistance you 
> > extended to me in 
> > my search for solution to my scripting problem. 
> > 
> > I did look at your suggestions and implemented it to my 
> > script specifically 
> > with CDO  and MS Outlook Object Libraries. 
> > 
> > Though my script is not fully automated as I would want it to 
> > be, with the 
> > use of Windows scheduled tasks and the Win32::GUITest module 
> > of Ernesto 
> > Guisado (thanks for the wonderful script), I did finally make 
> > my automailer 
> > script work as it should be. 
> > 
> > Again, to all many, many thanks. 
> > 
> > Rodel D. Bautista 
> > 
> > > -----Original Message----- 
> > > From:       Roy Sprague [SMTP:[EMAIL PROTECTED] 
> > > Sent:       Thursday, June 19, 2003 7:45 PM 
> > > To: 'Bautista, Rodel D.(Digitel-GSM)'; PERL-WIN32-USERS; 
> > > PERL-WIN32-USERS-A; perl-win32-users-admin 
> > > Subject:    RE: Using Outlook in Win32::OLE 
> > > 
> > > Try 
> > > 
> > <http://msdn.microsoft.com/library/default.asp?url=/library/en-> 
> > us/vbaol10/h 
> > > tm 
> > > l/olobjApplication.asp This site has all the available methods for 
> > > Outlook. 
> > > The examples are in VB but they can be converted to Perl.  
> > The following 
> > > code will open a list of pst files into Outlook. 
> > > 
> > > use Win32::OLE; 
> > > 
> > > $ol = Win32::OLE->CreateObject("Outlook.Application"); 
> > > $namespace = $ol->GetNamespace("MAPI"); 
> > > 
> > > open ( my $log, $ARGV[0] ) || print "Can't open $ARGV[0]\n"; 
> > > while ( <$log> ) 
> > > { 
> > >     chomp $_; 
> > >     my $file = "$_"; 
> > >     print "$file\n"; 
> > >     $namespace->AddStore ("$file"); 
> > > } 
> > > 
> > > undef $ol; 
> > > 
> > > 
> > > Roy Sprague, CISSP, MCSE, MCSA, HPASE 
> > > Senior Network Specialist 
> > > Landstar System Holdings, Inc. 
> > > 904 390-4860 
> > > 
> > >  -----Original Message----- 
> > > From:       Bautista, Rodel D.(Digitel-GSM) 
> > > [ <mailto:[EMAIL PROTECTED]>] 
> > > Sent:       Tuesday, June 17, 2003 1:07 AM 
> > > To: PERL-WIN32-USERS; PERL-WIN32-USERS-A; perl-win32-users-admin 
> > > Subject:    Using Outlook in Win32::OLE 
> > > 
> > > Hi All, 
> > > 
> > > I'm currently creating a mail sending script that uses 
> > Win32::OLE via MS 
> > > Outlook. I have already searched for an appropriate script 
> > but all that I 
> > > can find are programs that do not automatically connect to 
> > our Exchange 
> > > server. It asks first for a profile to use and then a logon dialog 
> > > appears. 
> > > 
> > > I'll appreciate much if someone could direct me to a 
> > document or site 
> > > where 
> > > a detailed discussion of Win32::OLE using MS Outlook is 
> > located or can be 
> > > found. 
> > > 
> > > TIA 
> > > 
> > > Rodel D. Bautista 
> > > 
> > > _______________________________________________ 
> > > Perl-Win32-Users mailing list 
> > > [EMAIL PROTECTED] 
> > > To unsubscribe: <http://listserv.ActiveState.com/mailman/mysubs> 
> > _______________________________________________ 
> > Perl-Win32-Users mailing list 
> > [EMAIL PROTECTED] 
> > To unsubscribe: <http://listserv.ActiveState.com/mailman/mysubs> 
> > 
> 
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to