Net::SMTP?

Robert L. Harris Robert.L.Harris at rdlg.net
Tue Jul 24 15:53:47 CDT 2001



Ok,  I actually ended up doing:

  my ($MessageBody)="We encountered some problems on $Hostname with:\n";
  foreach $i (@Down) {
    $MessageBody.="  $i\n";
  }

which is a bit ugly but it works.

I like the log option, but it doesn't print the message body, but I can
see what else it does. 

This is nice and clean.

Thanks,
  Robert


Thus spake Matthew J Long (matt.long at matthew-long.com):

> >From the example I provided, just do this:
> 
> ------------------------------------------------
> use Mail::Sendmail;
> 
> my $multiLineMessage =<<END_MSG;
>     Jim, we have problems.  The boxes in question are:
>     box1
>     box2
> END_MSG
> 
> %mail = ( To      => 'you at there.com',
>              Smtp    => 'your.smtp.server',
>              From    => 'me at here.com',
>              Message => $multiLineMessage              );
> 
> sendmail(%mail) or die $Mail::Sendmail::error;
> 
> print "OK. Log says:\n", $Mail::Sendmail::log;
> ---------------------------------------------------
> 
> -Matt
> 
> 
> ----- Original Message -----
> From: "Robert L. Harris" <Robert.L.Harris at rdlg.net>
> To: "Matthew J Long" <matt.long at matthew-long.com>
> Cc: "Robert L. Harris" <Robert.L.Harris at rdlg.net>; "Pikes-Peak Perl Mongers"
> <pikes-peak-pm-list at happyfunball.pm.org>
> Sent: Tuesday, July 24, 2001 1:26 PM
> Subject: Re: Net::SMTP?
> 
> 
> >
> >
> > How would you handle a multi-line message?  Soemthing like:
> >
> > Jim, we have problems.  The boxes in question are:
> >   box1
> >   box2
> >
> > etc.
> >
> > Thus spake Matthew J Long (matt.long at matthew-long.com):
> >
> > > I'm not completely sure I understand what all you are trying to do. If
> it's
> > > sending a message you want to do, use Mail::Sendmail instead. It will
> also
> > > support attachments.
> > >
> > > >From the Mail::Sendmail perldoc:
> > >
> > > ----------------------------------------------
> > >
> > > NAME
> > >     Mail::Sendmail v. 0.78 - Simple platform independent mailer
> > >
> > > SYNOPSIS
> > >       use Mail::Sendmail;
> > >
> > >       %mail = ( To      => 'you at there.com',
> > >                 Smtp    => 'your.smtp.server',
> > >                 From    => 'me at here.com',
> > >                 Message => "This is a very short message"
> > >                );
> > >
> > >       sendmail(%mail) or die $Mail::Sendmail::error;
> > >
> > >       print "OK. Log says:\n", $Mail::Sendmail::log;
> > >
> > > -----------------------------------------------------
> > > the Smtp field is only necessary if you're not using localhost.
> > >
> > > Good luck.
> > >
> > > -Matt
> > >
> > > ----- Original Message -----
> > > From: "Robert L. Harris" <Robert.L.Harris at rdlg.net>
> > > To: "Pikes-Peak Perl Mongers" <pikes-peak-pm-list at happyfunball.pm.org>
> > > Sent: Tuesday, July 24, 2001 12:51 PM
> > > Subject: Net::SMTP?
> > >
> > >
> > > >
> > > >
> > > > I'm trying to use Net::SMTP and I'm not getting any output.  Here's a
> > > > chunk of code:
> > > >
> > > >
> > > > #!/usr/local/bin/perl -w
> > > >
> > > > use strict;
> > > > use diagnostics;
> > > > use Net::SMTP;
> > > >
> > > > #
> > > > # Do some data gathering
> > > > #
> > > > .
> > > > .
> > > > .
> > > > #
> > > >
> > > >
> > > > if (@Down) {
> > > >   &SendMailNotification(@Down);
> > > > }
> > > >
> > > > exit 0;
> > > >
> > > > ########################
> > > > # Sub Procs below here #
> > > > ########################
> > > > sub SendMailNotification {
> > > >   my (@Down)=@_;
> > > >   my ($Hostname)=`hostname`;
> > > >   my ($MailSubject)="GonzoProblems on $Hostname";
> > > >   my ($MailTo)="robert\@rdlg.net";
> > > >   my ($i);
> > > >
> > > >   print "We had a problem so we'll send mail.\n";
> > > >
> > > >   $smtp = Net::SMTP->new('mailgw2.rdlg.net.');
> > > >
> > > >   $smtp->mail('GonzoChecker\@$Hostname');
> > > >   $smtp->to('robert at rdlg.net');
> > > >
> > > >   $smtp->data();
> > > >   $smtp->datasend("Subject: GonzoProblems on $Hostname\n");
> > > >   $smtp->datasend("\n");
> > > >   $smtp->datasend("Could not connect to:\n");
> > > >   foreach $i (@Down) {
> > > >     $smtp->datasend("$i\n");
> > > >   }
> > > >   $smtp->dataend();
> > > >
> > > >   $smtp->quit;
> > > >
> > > > #  open (SENDMAIL, "| /usr/bin/mailx -v -s \"$MailSubject\" $MailTo");
> > > > #
> > > > #  print "Could not connect to:\n";
> > > > #  print SENDMAIL "Could not connect to:\n";
> > > > #  foreach $i (@Down) {
> > > > #    print "  $i\n";
> > > > #    print SENDMAIL "  $i\n";
> > > > #  }
> > > > #  close(SENDMAIL);
> > > > }
> > > >
> > > > If I comment out the $smtp portion, and uncomment the other, it works
> just
> > > > fine.
> > > >
> > > >
> > > > :wq!
> > >
> > --------------------------------------------------------------------------
> > > -
> > > > Robert L. Harris                |  Micros~1 :
> > > > Senior System Engineer          |    For when quality, reliability
> > > >   at RnD Consulting             |      and security just aren't
> > > >                                 \_       that important!
> > > > DISCLAIMER:
> > > >       These are MY OPINIONS ALONE.  I speak for no-one else.
> > > > FYI:
> > > >  perl -e 'print
> > > $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
> > > >
> >
> >
> >
> > :wq!
> > --------------------------------------------------------------------------
> -
> > Robert L. Harris                |  Micros~1 :
> > Senior System Engineer          |    For when quality, reliability
> >   at RnD Consulting             |      and security just aren't
> >                                 \_       that important!
> > DISCLAIMER:
> >       These are MY OPINIONS ALONE.  I speak for no-one else.
> > FYI:
> >  perl -e 'print
> $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
> >



:wq!
---------------------------------------------------------------------------
Robert L. Harris                |  Micros~1 :  
Senior System Engineer          |    For when quality, reliability 
  at RnD Consulting             |      and security just aren't
                                \_       that important!
DISCLAIMER:
      These are MY OPINIONS ALONE.  I speak for no-one else.
FYI:
 perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'




More information about the Pikes-peak-pm mailing list