This is probably a very simple question or problem, but so far I've been going well and I need some extra eyes to guide me. I get an error at the 'Logon'. Here is the posted code. Perl 5.06.., on Win2000 Server
#!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);
Any help? Is this something simple I'm overlooking? I have sent email from my desktop with the working function in my code 'send_outlook_mail', but was trying to do it from one of our servers. So I went to www.deja.com and other sites to get help/information. I took the info from the MAPI connection and worked it around my send_outlook_mail function, knowing that the email sending works on my pc here. Thought if I made the connection on the server via MAPI in windows this could work. Is my thought on this and code way off?
Thank you all in advance for any/all help.
.Zo
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|