For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > October 2005 > Query on sendmail problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Query on sendmail problem
Dale

2005-10-05, 6:55 pm

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.
me@mydomain.co.uk) but also tried with \'s at appropriate places (e.g.
me\@mydomain\.co\.uk). 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: projectelf\@xxxxxxx\.co\.uk\n";
print MAIL "From: projectelf\@xxxxxxx\.co\.uk\n";
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);
-------------------------------------------------------------------------
-------------------------

--
Dale

Wiggins d'Anconia

2005-10-05, 6:55 pm

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.
> me@mydomain.co.uk) but also tried with 's at appropriate places (e.g.
> me\@mydomain\.co\.uk). I just can't get anything to work.
>
> Anyone have any ideas what I could be doing wrong.
>


You're not using a module... Don't think that is what you meant though.

> Thanks in advance!
>
> -------------------------------------------------------------------------
> -------------------------
> open(MAIL, "|/usr/local/bin/sendmail -t");
>
> print MAIL "To: $manageremail\n";


Are you chomp'ing $manageremail? If it has a newline on it in the file
and you have added an additional new line above then you have stopped
the header, surprisingly it should still be sending but below should be
in the body. You should probably have a look at the mail logs generated
by sendmail to see if it is complaining, and more specifically about what.

http://danconia.org

> # print MAIL "To: projectelf\@xxxxxxx\.co\.uk\n";
> print MAIL "From: projectelf\@xxxxxxx\.co\.uk\n";
> 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);
> -------------------------------------------------------------------------
> -------------------------
>

Scott R. Godin

2005-10-07, 6:55 pm

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.
> me@mydomain.co.uk) but also tried with 's at appropriate places (e.g.
> me\@mydomain\.co\.uk). 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: projectelf\@xxxxxxx\.co\.uk\n";
> print MAIL "From: projectelf\@xxxxxxx\.co\.uk\n";
> 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 ) =
('projectelf@xxxxx.co.uk', 'manager@xxxx.co.uk', '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.
Dale

2005-10-08, 3:55 am

Hi Wiggins d'Anconia, you wrote:

>Dale wrote:
>
>You're not using a module... Don't think that is what you meant though.


Thanks for looking at this for me!

I'm not using a module for this - took the instructions from a tutorial
site (though can't remember which one at the moment).

>
>Are you chomp'ing $manageremail? If it has a newline on it in the file
>and you have added an additional new line above then you have stopped
>the header, surprisingly it should still be sending but below should be
>in the body. You should probably have a look at the mail logs generated
>by sendmail to see if it is complaining, and more specifically about what.


$manageremail doesn't need chomping as it is in the middle of a comma
separated line of data.

(On a side note, when I read the last variable from a line of data, even
after chomping it, it still has a newline after it and I can't seem to
get rid of it!)
--
Dale - Liverpool, England

A menace to society - apparently!

Spam block: Please don't mail me with "abuse" - use my name instead!
Dale

2005-10-08, 3:55 am

Hi Scott R. Godin, you wrote:

>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 ) =
>('projectelf@xxxxx.co.uk', 'manager@xxxx.co.uk', 'Mr. Moribund', '',
>'');


Can I just check something on this as I'm a bit . I would just
read $manageremail and $manager from the data file wouldn't I? Or would
I need to have something like the following so it's part of the "my" :

my( $selfaddr, $manageremail2, $manager2, $somecondition, $bccaddress )
= ('projectelf@xxxxx.co.uk', $manageremail, $manager, '', '');

Or... since the next section has $manageremail in it, can I leave it out
of the "my" and just take it that the Cc => $manageremail will accept
what I've already got it to read from the datafile? (Hope that makes
sense *grin*)

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


*Snip*

>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.


Thanks for the examples and the links - I really appreciate the help,
especially as I actually understood the excellent example as well! :)
I'll certainly read through the links you've been kind enough to
include.
--
Dale - Liverpool, England

A menace to society - apparently!
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com