The easier way, and way that I use on my systems, is with Net::SMTP if you have a SMTP server on you enviroment. The other way is to use OLE to talk with Outlook or any other email client, but this is the hard way, very hard :)
Solli Moreira Honorio
Sao Paulo - Brazil
| [reply] |
use Email::Send;
my $message = <<'__MESSAGE__';
To: recipient@example.com
From: sender@example.com
Subject: Hello there folks
How are you? Enjoy!
__MESSAGE__
my $sender = Email::Send->new({mailer => 'SMTP'});
$sender->mailer_args([Host => 'smtp.example.com']);
$sender->send($message);
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
| [reply] [d/l] |
| [reply] |
Here's one way. Please note that this was just pulled from some code I had lying around that sends an email through outlook (contrary to some of my contemporaries it wasn't really all that hard ;-) - as such, there are a few functions referenced in this snippet that are not provided.
my( $outlook, $message ) = open_outlook();
build_email( $message, $maindate, $file );
send_email( $message );
sub build_email {
my( $message, $date, $file ) = @_;
my $displaydate = format_date( $date );
$message->{'To'} = q{toaddress@domain.com};
$message->{'Subject'} = q{This is the subject};
( $message->{'Body'} =<<" EOBODY" ) =~ s/^ //gm;
blah blah blah
EOBODY
my $attachment = $message->Attachments();
$attachment->Add( $file );
return 1;
}
sub send_email {
my $message = shift;
$message->Send();
return 1;
}
sub open_outlook {
my $outlook = Win32::OLE->GetActiveObject( 'Outlook.Application' )
|| Win32::OLE->new( 'Outlook.Application', \&OleQuit )
|| die "can't create Outlook.Application: is it installed? : $!
+: $^E";
my $message = $outlook->CreateItem(0)
|| die "can't create new message : $! : $^E";
return( $outlook, $message );
}
--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; =
qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
| [reply] [d/l] [select] |
here using CDO that now ship with xp e 2k3 instead of CDONTS. This code run without an SMPT on local machine specifiing a mail server. #!perl
use strict;
use warnings;#amen
use Win32::OLE ;
my $Message = Win32::OLE->new("CDO.Message");
#francobollo means stamp...
my $francobollo= Win32::OLE->new ("CDO.Configuration") ;
$francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi
+guration/sendusing"}=2;#means with no local SMTP srv
$francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi
+guration/smtpserver"}="mail.server.you.can.use.net";
$francobollo->{Fields}->{"http://schemas.microsoft.com/cdo/confi
+guration/smtpserverport"}=25;
$francobollo->{Fields}->Update();
$Message->{Configuration} = $francobollo;
$Message->{From}="me\@peacefull-place.org";
$Message->{To}="you\@in-a-dog-hell.com";
$Message->{Bcc}="your-assistant\@angel.net";
$Message->{Subject}="I told you, myDeamon, to run on a Linux machine."
+;
$Message->{TextBody}="ah ahah ahaha aha ahhha \n";
$Message->Send();
HTH Lorenzo* | [reply] [d/l] |
there is also a commercial sendmail equivalent for windows (google it), but from my experience its more trouble than its worth. Net::SMTP is the better choice, as other monks have suggested.
__________ The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.
- Terry Pratchett
| [reply] |
Thanks for all of your advice, I will try and let you know the result
| [reply] |
Been a while since I used it, but I used to do it
like this...
My Script Here
...for monitoring ongoing tests from my home an hour away.
That script checks a log file every N minutes for updates, then emails it if changed. Steal anything you want out of there if it suits your needs.
| [reply] |