Dale wrote:
Hi,

I'm hoping someone can help me with an issue I've got with, I assume,
sendmail.

I've copied part of a script below.  If I use the first To: line (which
takes the e-mail address from a file - and this works) then a mail
doesn't arrive.  If, however, I used the second To: line (which is
currently commented out - the xxxxxx is to stop spammers picking the
address up from this mail) then a mail is received.

I added a page after the sendmail just to make sure it was reading the
e-mail address from the file (which it was) but it still doesn't seem to
send. $manageremail is the correct variable name.

In the datafile, I've had the e-mail addresses formatted properly (e.g.
[EMAIL PROTECTED]) but also tried with \'s at appropriate places (e.g.
[EMAIL PROTECTED]).  I just can't get anything to work.

Anyone have any ideas what I could be doing wrong.

Thanks in advance!

-------------------------------------------------------------------------
-------------------------
  open(MAIL, "|/usr/local/bin/sendmail -t");

    print MAIL "To: $manageremail\n";
#   print MAIL "To: [EMAIL PROTECTED]";
    print MAIL "From: [EMAIL PROTECTED]";
    print MAIL "Subject: Escalation logged\n";

    print MAIL "Hi $manager\.\n\n";
    print MAIL "The following escalation has been logged from your
team.\n\n";
    print MAIL "Agent's Manager   : $manager\n";
    print MAIL "Agent's Name      : $agentname\n";
    print MAIL "Date Logged       : $day\-$month\-$year\n";
    print MAIL "Escalation Reason : $reason\n";
    print MAIL "Short Description : $short\n";
    print MAIL "Long  Description : $long\n";
    print MAIL "Justified?        : $justified\n";
    print MAIL "Name of Logger    : $logger\n";

  close (MAIL);
-------------------------------------------------------------------------
-------------------------


I'd more likely be using Mail::Mailer or MIME::Lite as the interface is quite clean and straightforward.

example

#!/usr/bin/perl -T
use warnings;
use strict;
use MIME::Lite

# this data will come from somewhere else in your program flow
my %escalation = (
        manager         => '',
        agentname       => '',
        logger          => '',
        datelogged      => '',
        reason          => '',
        justify         => '',
        shortdesc       => '',
        longdesc        => '',
);

my( $selfaddr, $manageremail, $manager, $somecondition, $bccaddress ) = ('[EMAIL PROTECTED]', '[EMAIL PROTECTED]', 'Mr. Moribund', '', '');

my $msg = MIME::Lite->new(
        From    => $selfaddr,
        To      => $selfaddr,
        Cc      => $manageremail,
        Subject => 'Escalation Logged',
        Type    => 'multipart/mixed',
);

if ($somecondition) {
        $msg->add( 'Bcc' => '$ccaddress');
}

my $message = <<"END":

Attention $manager,

The following esclation has been logged from your team:

Agent's Manager:   $escalation{manager}
Agent's Name:      $escalation{agentname}
Name of Logger:    $escalation{logger}
Date Logged:       $escalation{datelogged}
Escalation Reason: $escalation{reason}
Justification:     $escalation{justify}
Short Description: $escalation{shortdesc}
Long Description:  $escalation{longdesc}

END

$msg->attach(
        Type    => 'TEXT',
        Data    => $message,
);

$msg->send;

__END__

For html-type messages (created via CGI.pm's function-oriented interface, for example), you can also in addition to the plaintext, attach a html-format copy thusly:

#very very simplistic example -- you can embed css and images as well
push @myarray,
        start_html(
                -style=>{-code=>$stylesheet},
                -title=>"Escalation Alert",
        ),
        div({-id="Container"},
                h1({-class=>'alert'}, "header"),
                p("content"),
        ),
        end_html();

$msg->attach(
        Type    => 'text/html',
        Disposition     => 'attachment',
        Encoding        => 'quoted-printable',
        Data    => @myarray,
        Filename        => 'escalation.htm',
);

..for example.

MIME::Lite has many more details you can manipulate, attaching image/pdf/log files, or as illustrated above, sending both plaintext/html-based messages...

http://search.cpan.org/~yves/MIME-Lite-3.01/ for details.

Mail::Mailer (which I mentioned earlier) is part of the MailTools package, which you can look over, here: http://search.cpan.org/~markov/MailTools-1.67/

It's rare I'll try and hit up sendmail directly as you have done, when there are mechanisms such as these to do it more cleanly and with more control.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to