RE: Using Outlook in Win32::OLE

2003-06-22 Thread Bautista, Rodel D.\(Digitel-GSM\)
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

RE: Using Outlook in Win32::OLE

2003-06-19 Thread Herold Heiko
Try using windows style slashes -
'c:\audit\IN\mail_scripts\auto_mail.pl'
Heiko

-- 
-- PREVINET S.p.A. www.previnet.it
-- Heiko Herold [EMAIL PROTECTED]
-- +39-041-5907073 ph
-- +39-041-5907472 fax

 -Original Message-
 From: Bautista, Rodel D.(Digitel-GSM) 
 [mailto:[EMAIL PROTECTED]
 Sent: Thursday, June 19, 2003 4:59 AM
 To: Charbeneau, Chuck
 Cc: PERL-WIN32-USERS
 Subject: RE: Using Outlook in Win32::OLE
 
 
 Sir, I've tried the following script below and here is the result.
 
 a) the mapis32.exe process is started by the script so I am 
 automatically
 authenticated (w/o outlook running) and send the mail successfully.
 b) when I tried attaching a file, the mail was not sent and 
 an undeliverable
 message appears in my personal folder (my outlook is 
 configured such that
 when i opened it all my mails are transferred to my personal 
 folder). the
 part where I attach a file is not working (commented the part for file
 attachment). Can you give me a sample of code that I can use? 
 I've already
 searched in the OLE-Browser html and I used the objects 
 indicated there but
 still I'm not successful in file attachments. Here is the 
 error message from
 the undeliverable mail:
 
 # start of message body
 
 Your message did not reach some or all of the intended recipients.
 
   Subject:Test
   Sent:   6/19/2003 10:38 AM
 
 The following recipient(s) could not be reached:
 
   'Rodel Bautista' on 6/19/2003 10:38 AM
 No transport provider was available for delivery to this
 recipient.
 
 # end of message body
 
 Note that I'm using Outlook 97, ActivePerl 5.6.1 build 635, Windows XP
 Professional.
 
 Here is the script (taken from the pdf file of David N. 
 Blank-Edelman posted
 as Perl for System Administration: Networking Power Hour - Electronic
 Mail):
 
 #! c:\perl\bin\perl
 
 $to=recipient_name;
 $subject=Test;
 $body=This is a test message\n;
 use Win32::OLE;
 Win32::OLE-Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
 my $session = Win32::OLE-new('MAPI.Session','Logoff');
 die Win32::OLE-LastError(),\n if Win32::OLE-LastError();
 $session-Logon('profile_name','password','False');
 my $message = $session-Outbox-Messages-Add;
 my $recipient = $message-Recipients-Add;
 $recipient-{Name} = $to;
 $recipient-{Type} = 1; # 1 = To:, 2 = Cc:, 3 = Bcc:
 $recipient-Resolve();
 $message-{Subject} = $subject;
 $message-{Text} = $body;
 
 #$message-Attachments-Add('c:/audit/IN/mail_scripts/auto_mai
 l.pl',1,0,'aut
 o_mail.pl');
 
 $message-Update;
 
 $message-Send(0, 0, 0); # now it has been _queued_
 undef $session;
 
 #end of script
 
 Can you help me again on this.
 
 Thank you very much.
 
 Rodel D. Bautista
 
  -Original Message-
  From:   Charbeneau, Chuck [SMTP:[EMAIL PROTECTED]
  Sent:   Wednesday, June 18, 2003 8:13 PM
  To: 'Bautista, Rodel D.(Digitel-GSM)'
  Subject:RE: Using Outlook in Win32::OLE
  
  
   From: Bautista, Rodel D.(Digitel-GSM) 
   Subject: RE: Using Outlook in Win32::OLE
   
   
   Sir, in as much as I would like to just connect directly to 
   our exchange server via smtp, we are not allowed to do so by 
   our security dept. I'll just be using the script on one 
   machine to automate the mailing of daily logs to our boss. 
  
  *Ouch*
  
  In that case, the suggestions that were made regarding 
 scripting reference
  and the use of constants would be best followed before 
 going much further.
  
  Joe Frazier probably gives the best example.
  
  You would do well with a decent object reference as well, 
 to help make
  sense
  of the Outlook class structure, and if you don't have VB 
 installed such
  that
  you can use the browser there, Jan Dubois created an 
 excellent web based
  one
  that ships with Activestate's perl port.
  
  If you have Activestate installed, you can probably find it in:
  
  PERLROOT\html\OLE-Browser\browser.html
  
  Scroll down to the Microsoft Outlook objects and look at the
  implementation
  methods for the objects that Joe suggested.
  
  I haven't actually written code to deal with 
 authentication, since I'm
  always authenticated, but if you need help, I'm sure I can 
 crack some out.
  Lord knows I've written plenty of other Outlook handling code.
  
  Let us know what you come up with and if you run into any log jams.
  
  Chuck Charbeneau
  Lear Corporation
  Lead Software Applications Engineer
  ccharbeneau at lear dot com
  
  **
  ** LEGAL DISCLAIMER **
  **
  
  This E-mail message and any attachments may contain 
  legally privileged, confidential or proprietary 
  information. If you are not the intended recipient(s),
  or the employee or agent responsible for delivery of 
  this message to the intended recipient(s), you are 
  hereby notified that any dissemination, distribution 
  or copying of this E-mail message is strictly 
  prohibited. If you have received this message in 
  error, please immediately notify the sender and 
  delete

RE: Using Outlook in Win32::OLE

2003-06-19 Thread Roy Sprague
Try
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaol10/htm
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


RE: Using Outlook in Win32::OLE

2003-06-18 Thread Bautista, Rodel D.\(Digitel-GSM\)
Sir, again thank you very much for your help (and for everyone who shared
some of their time replying to my queries and assisting in my problem). I'll
try to look at your suggestion and advice.

Actually, I have already a script that handles the authentication part but
the problem now is that when I've tried running the script, the mail is now
in my inbox (personal folders) indicating an error in sending when I opened
outlook. I've noticed this problem occurs when mapisp32.exe is not running
as a process (checked this in task manager). When I tried running the script
the 2nd time (with mapisp32.exe running and outlook is now closed), the mail
is sent successfully, the mail now is in the servers mailbox. (Note that
there are no errors indicated in the console when I runned the script.)

here is the code (I've found this in one of my googling and modified a part
of it for my requirements - thank you very much for the one who made the
script):

#! c:/perl/bin/perl

@attachment = ('somefile.pl');
$AttachmentArraySize = @attachment - 1;
$attcount = @attachment;

$sender = profile_name;
$passwd = profile_password;

print \n*** Automailer of Logs ***\n\n;
use Win32::OLE qw(in with);
use Win32::OLE::Variant;
Win32::OLE-Initialize(Win32::OLE::COINIT_OLEINITIALIZE);

print Opening MAPI session...\n\n;
$session = Win32::OLE-new(MAPI.Session)
or die Could not create a new MAPI Session: $!  .
Win32::OLE-LastError(0);
print Logging to Outlook...\n\n;
my $err = $session-Logon($sender, $passwd, False);
if ($err) {die Logon failed: $!;}

print Creating new message...\n\n;
$msg = $session-Outbox-Messages-Add();

print Adding recipients...\n\n;
$rcpt = $msg-Recipients-Add();
$rcpt-{Name} = 'recipient_name';
$rcpt-{Type} = 1;
$rcpt-Resolve();

print Adding subject and text body...\n\n;
$msg-{Subject} = Test message with attachments using Perl;
$msg-{Text} = EOF;
Please find attached a several reports sent via MAPI and Perl.

If you are reading this message and you can view the message attachment
then the code is working properly to send e-mail reports through Microsoft
Exchange.

Feel free to delete this message.

This has been a test.

Rodel
EOF

print Attaching files to be sent...\n\n;
$ctr = 0;
foreach $attachment(0..$AttachmentArraySize) {
#print Attaching file: $attachment[$ctr] \n;
$att = $msg-Attachments-Add();
$att-{name} = Variant(VT_BSTR, $attachment[$ctr]);
$att-{type} = Variant(VT_I2|VT_BYREF,1);
$att-{source} = Variant(VT_BSTR|VT_BYREF, $attachment[$ctr]);
$att-{position} = Variant(VT_R8|VT_BYREF, (2880 * $ctr) );
$ctr++;
}

$msg-Update();
print Sending mail...\n\n;
$msg-Send(0, 0, 0);
print Closing MAPI session...\n\n;
$session-Logoff();

exit 0;

Is there a way for me to check if mapisp32.exe is running and if not run
this program so that it will work fine.

I've also encountered a problem with the attachment, it cannot be opened or
saved.

with much appreciation.

Rodel D. Bautista

 -Original Message-
 From: Charbeneau, Chuck [SMTP:[EMAIL PROTECTED]
 Sent: Wednesday, June 18, 2003 8:13 PM
 To:   'Bautista, Rodel D.(Digitel-GSM)'
 Subject:  RE: Using Outlook in Win32::OLE
 
 
  From: Bautista, Rodel D.(Digitel-GSM) 
  Subject: RE: Using Outlook in Win32::OLE
  
  
  Sir, in as much as I would like to just connect directly to 
  our exchange server via smtp, we are not allowed to do so by 
  our security dept. I'll just be using the script on one 
  machine to automate the mailing of daily logs to our boss. 
 
 *Ouch*
 
 In that case, the suggestions that were made regarding scripting reference
 and the use of constants would be best followed before going much further.
 
 Joe Frazier probably gives the best example.
 
 You would do well with a decent object reference as well, to help make
 sense
 of the Outlook class structure, and if you don't have VB installed such
 that
 you can use the browser there, Jan Dubois created an excellent web based
 one
 that ships with Activestate's perl port.
 
 If you have Activestate installed, you can probably find it in:
 
 PERLROOT\html\OLE-Browser\browser.html
 
 Scroll down to the Microsoft Outlook objects and look at the
 implementation
 methods for the objects that Joe suggested.
 
 I haven't actually written code to deal with authentication, since I'm
 always authenticated, but if you need help, I'm sure I can crack some out.
 Lord knows I've written plenty of other Outlook handling code.
 
 Let us know what you come up with and if you run into any log jams.
 
 Chuck Charbeneau
 Lear Corporation
 Lead Software Applications Engineer
 ccharbeneau at lear dot com
 
 **
 ** LEGAL DISCLAIMER **
 **
 
 This E-mail message and any attachments may contain 
 legally privileged, confidential or proprietary 
 information. If you are not the intended recipient(s),
 or the employee or agent responsible for delivery of 
 this message to the intended recipient(s), you are 
 hereby notified that any dissemination, distribution

RE: Using Outlook in Win32::OLE

2003-06-18 Thread Bautista, Rodel D.\(Digitel-GSM\)
Sir, in one of my googling sessions, I run into Win32::MAPI module. Will
this help me in my automailer script? Where can I find and download the
module?

again, thank you very much.

Rodel D. Bautista

 -Original Message-
 From: Bautista, Rodel D.(Digitel-GSM) [SMTP:[EMAIL PROTECTED]
 Sent: Thursday, June 19, 2003 8:05 AM
 To:   Charbeneau, Chuck
 Cc:   PERL-WIN32-USERS
 Subject:  RE: Using Outlook in Win32::OLE
 
 Sir, again thank you very much for your help (and for everyone who shared
 some of their time replying to my queries and assisting in my problem).
 I'll
 try to look at your suggestion and advice.
 
 Actually, I have already a script that handles the authentication part but
 the problem now is that when I've tried running the script, the mail is
 now
 in my inbox (personal folders) indicating an error in sending when I
 opened
 outlook. I've noticed this problem occurs when mapisp32.exe is not
 running
 as a process (checked this in task manager). When I tried running the
 script
 the 2nd time (with mapisp32.exe running and outlook is now closed), the
 mail
 is sent successfully, the mail now is in the servers mailbox. (Note that
 there are no errors indicated in the console when I runned the script.)
 
 here is the code (I've found this in one of my googling and modified a
 part
 of it for my requirements - thank you very much for the one who made the
 script):
 
 #! c:/perl/bin/perl
 
 @attachment = ('somefile.pl');
 $AttachmentArraySize = @attachment - 1;
 $attcount = @attachment;
 
 $sender = profile_name;
 $passwd = profile_password;
 
 print \n*** Automailer of Logs ***\n\n;
 use Win32::OLE qw(in with);
 use Win32::OLE::Variant;
 Win32::OLE-Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
 
 print Opening MAPI session...\n\n;
 $session = Win32::OLE-new(MAPI.Session)
 or die Could not create a new MAPI Session: $!  .
 Win32::OLE-LastError(0);
 print Logging to Outlook...\n\n;
 my $err = $session-Logon($sender, $passwd, False);
 if ($err) {die Logon failed: $!;}
 
 print Creating new message...\n\n;
 $msg = $session-Outbox-Messages-Add();
 
 print Adding recipients...\n\n;
 $rcpt = $msg-Recipients-Add();
 $rcpt-{Name} = 'recipient_name';
 $rcpt-{Type} = 1;
 $rcpt-Resolve();
 
 print Adding subject and text body...\n\n;
 $msg-{Subject} = Test message with attachments using Perl;
 $msg-{Text} = EOF;
 Please find attached a several reports sent via MAPI and Perl.
 
 If you are reading this message and you can view the message attachment
 then the code is working properly to send e-mail reports through Microsoft
 Exchange.
 
 Feel free to delete this message.
 
 This has been a test.
 
 Rodel
 EOF
 
 print Attaching files to be sent...\n\n;
 $ctr = 0;
 foreach $attachment(0..$AttachmentArraySize) {
 #print Attaching file: $attachment[$ctr] \n;
 $att = $msg-Attachments-Add();
 $att-{name} = Variant(VT_BSTR, $attachment[$ctr]);
 $att-{type} = Variant(VT_I2|VT_BYREF,1);
 $att-{source} = Variant(VT_BSTR|VT_BYREF, $attachment[$ctr]);
 $att-{position} = Variant(VT_R8|VT_BYREF, (2880 * $ctr) );
 $ctr++;
 }
 
 $msg-Update();
 print Sending mail...\n\n;
 $msg-Send(0, 0, 0);
 print Closing MAPI session...\n\n;
 $session-Logoff();
 
 exit 0;
 
 Is there a way for me to check if mapisp32.exe is running and if not run
 this program so that it will work fine.
 
 I've also encountered a problem with the attachment, it cannot be opened
 or
 saved.
 
 with much appreciation.
 
 Rodel D. Bautista
 
  -Original Message-
  From:   Charbeneau, Chuck [SMTP:[EMAIL PROTECTED]
  Sent:   Wednesday, June 18, 2003 8:13 PM
  To: 'Bautista, Rodel D.(Digitel-GSM)'
  Subject:RE: Using Outlook in Win32::OLE
  
  
   From: Bautista, Rodel D.(Digitel-GSM) 
   Subject: RE: Using Outlook in Win32::OLE
   
   
   Sir, in as much as I would like to just connect directly to 
   our exchange server via smtp, we are not allowed to do so by 
   our security dept. I'll just be using the script on one 
   machine to automate the mailing of daily logs to our boss. 
  
  *Ouch*
  
  In that case, the suggestions that were made regarding scripting
 reference
  and the use of constants would be best followed before going much
 further.
  
  Joe Frazier probably gives the best example.
  
  You would do well with a decent object reference as well, to help make
  sense
  of the Outlook class structure, and if you don't have VB installed such
  that
  you can use the browser there, Jan Dubois created an excellent web based
  one
  that ships with Activestate's perl port.
  
  If you have Activestate installed, you can probably find it in:
  
  PERLROOT\html\OLE-Browser\browser.html
  
  Scroll down to the Microsoft Outlook objects and look at the
  implementation
  methods for the objects that Joe suggested.
  
  I haven't actually written code to deal with authentication, since I'm
  always authenticated, but if you need help, I'm sure I can crack some
 out.
  Lord knows I've written plenty of other Outlook handling

RE: Using Outlook in Win32::OLE

2003-06-18 Thread Bautista, Rodel D.\(Digitel-GSM\)
Sir, I've tried the following script below and here is the result.

a) the mapis32.exe process is started by the script so I am automatically
authenticated (w/o outlook running) and send the mail successfully.
b) when I tried attaching a file, the mail was not sent and an undeliverable
message appears in my personal folder (my outlook is configured such that
when i opened it all my mails are transferred to my personal folder). the
part where I attach a file is not working (commented the part for file
attachment). Can you give me a sample of code that I can use? I've already
searched in the OLE-Browser html and I used the objects indicated there but
still I'm not successful in file attachments. Here is the error message from
the undeliverable mail:

# start of message body

Your message did not reach some or all of the intended recipients.

  Subject:  Test
  Sent: 6/19/2003 10:38 AM

The following recipient(s) could not be reached:

  'Rodel Bautista' on 6/19/2003 10:38 AM
No transport provider was available for delivery to this
recipient.

# end of message body

Note that I'm using Outlook 97, ActivePerl 5.6.1 build 635, Windows XP
Professional.

Here is the script (taken from the pdf file of David N. Blank-Edelman posted
as Perl for System Administration: Networking Power Hour - Electronic
Mail):

#! c:\perl\bin\perl

$to=recipient_name;
$subject=Test;
$body=This is a test message\n;
use Win32::OLE;
Win32::OLE-Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
my $session = Win32::OLE-new('MAPI.Session','Logoff');
die Win32::OLE-LastError(),\n if Win32::OLE-LastError();
$session-Logon('profile_name','password','False');
my $message = $session-Outbox-Messages-Add;
my $recipient = $message-Recipients-Add;
$recipient-{Name} = $to;
$recipient-{Type} = 1; # 1 = To:, 2 = Cc:, 3 = Bcc:
$recipient-Resolve();
$message-{Subject} = $subject;
$message-{Text} = $body;

#$message-Attachments-Add('c:/audit/IN/mail_scripts/auto_mail.pl',1,0,'aut
o_mail.pl');

$message-Update;

$message-Send(0, 0, 0); # now it has been _queued_
undef $session;

#end of script

Can you help me again on this.

Thank you very much.

Rodel D. Bautista

 -Original Message-
 From: Charbeneau, Chuck [SMTP:[EMAIL PROTECTED]
 Sent: Wednesday, June 18, 2003 8:13 PM
 To:   'Bautista, Rodel D.(Digitel-GSM)'
 Subject:  RE: Using Outlook in Win32::OLE
 
 
  From: Bautista, Rodel D.(Digitel-GSM) 
  Subject: RE: Using Outlook in Win32::OLE
  
  
  Sir, in as much as I would like to just connect directly to 
  our exchange server via smtp, we are not allowed to do so by 
  our security dept. I'll just be using the script on one 
  machine to automate the mailing of daily logs to our boss. 
 
 *Ouch*
 
 In that case, the suggestions that were made regarding scripting reference
 and the use of constants would be best followed before going much further.
 
 Joe Frazier probably gives the best example.
 
 You would do well with a decent object reference as well, to help make
 sense
 of the Outlook class structure, and if you don't have VB installed such
 that
 you can use the browser there, Jan Dubois created an excellent web based
 one
 that ships with Activestate's perl port.
 
 If you have Activestate installed, you can probably find it in:
 
 PERLROOT\html\OLE-Browser\browser.html
 
 Scroll down to the Microsoft Outlook objects and look at the
 implementation
 methods for the objects that Joe suggested.
 
 I haven't actually written code to deal with authentication, since I'm
 always authenticated, but if you need help, I'm sure I can crack some out.
 Lord knows I've written plenty of other Outlook handling code.
 
 Let us know what you come up with and if you run into any log jams.
 
 Chuck Charbeneau
 Lear Corporation
 Lead Software Applications Engineer
 ccharbeneau at lear dot com
 
 **
 ** LEGAL DISCLAIMER **
 **
 
 This E-mail message and any attachments may contain 
 legally privileged, confidential or proprietary 
 information. If you are not the intended recipient(s),
 or the employee or agent responsible for delivery of 
 this message to the intended recipient(s), you are 
 hereby notified that any dissemination, distribution 
 or copying of this E-mail message is strictly 
 prohibited. If you have received this message in 
 error, please immediately notify the sender and 
 delete this E-mail message from your computer.
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Using Outlook in Win32::OLE

2003-06-17 Thread Charbeneau, Chuck

 From: Bautista, Rodel D.(Digitel-GSM) 
 Subject: FW: Using Outlook in Win32::OLE

 I'm entirely at a loss here. I'm in dire need of help with my 
 problem below. I've tried searching for a perl script that 
 automatically connect/log me to an outlook application and 
 send a mail with an attachment but all I found was a script 
 that asks me for a profile and logon info before actually 
 sending the mail.


Maybe I'm missing the point, but why would you want the overhead of using
Outlook, when you could just connect to the Exchange server as an SMTP
server and send a MIME encoded email that way?  The code would be platform
independent, smaller, and not require Outlook be installed on any machine
that wants to use it?

Chuck Charbeneau
Lear Corporation
Lead Software Applications Engineer
ccharbeneau at lear dot com

**
** LEGAL DISCLAIMER **
**

This E-mail message and any attachments may contain 
legally privileged, confidential or proprietary 
information. If you are not the intended recipient(s),
or the employee or agent responsible for delivery of 
this message to the intended recipient(s), you are 
hereby notified that any dissemination, distribution 
or copying of this E-mail message is strictly 
prohibited. If you have received this message in 
error, please immediately notify the sender and 
delete this E-mail message from your computer.
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Using Outlook in Win32::OLE

2003-06-17 Thread Herold Heiko
Works fine for me.
Check the configuration of outlook.
Try checking if outlook is configured for asking which profile to use when
opened.
Try the whole thing with outlook already open, in that case you shouldn't
get the profile prompt since at first you try to reuse an existing session
with Win32::OLE-GetActiveObject('Outlook.Application').

Oh, and instead of 
$mail-CreateItem(0)
generally you'll want to use
use Win32::OLE::Const;
$outlookconst= Win32::OLE::Const-Load(Microsoft Outlook);
$mail-CreateItem($outlookconst-{olMailItem});

However the other posters point is valid.
By using directly outlook you gain something (you can use custom forms and
other features not available with smtp, but possibly useful/needed in a more
complex outlook/exchange environment; you generate na email which will not
lost if the smtp server is presently unavailable, since later / at te next
session outlook will retry).
On the other hand you open a whole can of worms, like outlook being present
but currently blocked (uninterruptable user dialogue present due to user
working and similar, which will hang your application, too), bugs (much more
complex invironment = more bugs) and so on, which could cost you more than
you gain if you just need to send a simple email with some attachments -
look into blat.
Or look into the CDO object model (instead of outlook objects) if you need
to use this only from some machines you have control over, or if you can
deploy cdo with your outlook installation. On the other hand with cdo you
won't (I believe) be able to use custom forms.

Heiko 

-- 
-- PREVINET S.p.A. www.previnet.it
-- Heiko Herold [EMAIL PROTECTED]
-- +39-041-5907073 ph
-- +39-041-5907472 fax

 -Original Message-
 From: Bautista, Rodel D.(Digitel-GSM) 
 [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, June 17, 2003 9:19 AM
 To: PERL-WIN32-USERS
 Subject: FW: Using Outlook in Win32::OLE
 
 
 Hi All,
 
 I'm entirely at a loss here. I'm in dire need of help with my 
 problem below.
 I've tried searching for a perl script that automatically 
 connect/log me to
 an outlook application and send a mail with an attachment but 
 all I found
 was a script that asks me for a profile and logon info before actually
 sending the mail.
 
 Any help will be highly appreciated. 
 
 here is a snippet of the code.
 
 #! c:/Perl/bin/perl
 
 use Win32::OLE;
 
 $to = recipient_name;
 $subject = subject;
 $body = message_body;
 $cc = ;
 
 #get new Outlook instance
 $mail = Win32::OLE-GetActiveObject('Outlook.Application')
|| Win32::OLE-new('Outlook.Application', 'Quit');
 die Unable to start Outlook instance: $! if !defined $mail;
 
 $item = $mail-CreateItem(0);
 die Unable to create mail item: $! if !defined $item;
 
 $item-{'To'} = $to; 
 $item-{'CC'} = $cc;
 $item-{'Subject'} = $subject;
 $item-{'Body'} = $body; 
 
 #rest of args are file attachments
 foreach $attach (file_attach)
 {
 #make sure the attachment is really there
 die Missing attachment $attach: $! if !-e $attach;
 
 $attachments = $item-Attachments();
 $attachments-Add($attach);
 }
 
 #send it
 $item-Send();
 
 $error = Win32::OLE-LastError();
 print STDERR Win32::OLE error: $error if $error;
 
 
 
  -Original Message-
  From:   Bautista, Rodel D.(Digitel-GSM) 
 [SMTP:[EMAIL PROTECTED]
  Sent:   Tuesday, June 17, 2003 1:07 PM
  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