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

Reply via email to