Pipe outputs response to browser

  • Thread starter Experienced but Undocumented
  • Start date
E

Experienced but Undocumented

I'm using the following script which outputs the response from the SMTP
server to the browser. What should I do to make it work silently? Using
PERL 5.6.1 on Redhat Linux 7.3.
Thanks



open(MAIL, "|/usr/sbin/sendmail -bs") or die "Could not launch Mailer";

print MAIL "HELO LONGLOSTFRIEND\n";
print MAIL "MAIL FROM: $mailfrom\n";
print MAIL "$rcpt_to";
print MAIL "DATA\n";
print MAIL "From: $from\n";
print MAIL "Reply-to: $replyto\n";
print MAIL "Bcc:\n";
print MAIL "Subject: $subject\n";
print MAIL "\n";
print MAIL "$message\n";
print MAIL ".\n";
print MAIL "QUIT\n";

close MAIL;
 
J

Joe Smith

Experienced said:
print MAIL "HELO LONGLOSTFRIEND\n";
print MAIL "MAIL FROM: $mailfrom\n";
print MAIL "$rcpt_to";
print MAIL "DATA\n";
...
print MAIL ".\n";
print MAIL "QUIT\n";

That sort of SMTP dialog is what you send to a socket connected to
TCP port 25. You do _not_ send that to a pipe to sendmail!

open(MAIL, "|/usr/sbin/sendmail -oi -t") or die "Could not launch Mailer";
print MAIL <<EOM;
From: $from
Reply-to: $replyto
Subject: $subject

$message
EOM
 
T

Tintin

Experienced but Undocumented said:
I'm using the following script which outputs the response from the SMTP
server to the browser. What should I do to make it work silently? Using
PERL 5.6.1 on Redhat Linux 7.3.

You're not connecting to a SMTP server, you're connecting to a MTA.
 
E

Experienced but Undocumented

Tintin said:
You're not connecting to a SMTP server, you're connecting to a MTA.


I was curious about that; the admin at my web host told me to do it this way
because I was sending the same message to multiple recipients ("RCPT TO:
<[email protected]>\nRCPT TO: <[email protected]>\nRCPT TO: <[email protected]>\n")

Are there any better ways? My mailing list is about 100 people and could
potentially grow to 5-600.

Thanks
 
J

James Willmore

I'm using the following script which outputs the response from the SMTP
server to the browser. What should I do to make it work silently? Using
PERL 5.6.1 on Redhat Linux 7.3.

[ ...]

Wrap the code in an 'eval'.

---code---
eval{
open(MAIL, "|/usr/sbin/sendmail -bs") or die "Could not launch Mailer";

print MAIL "HELO LONGLOSTFRIEND\n";
print MAIL "MAIL FROM: $mailfrom\n";
print MAIL "$rcpt_to";
print MAIL "DATA\n";
print MAIL "From: $from\n";
print MAIL "Reply-to: $replyto\n";
print MAIL "Bcc:\n";
print MAIL "Subject: $subject\n";
print MAIL "\n";
print MAIL "$message\n";
print MAIL ".\n";
print MAIL "QUIT\n";

close MAIL;
};

die "Content-type: text/html\n\nCouldn't send email\n" if $@;

print "Content-type: text/html\n\n Email sent\n";
--end code--

This code is untested and off the top of my head. I prefer to use the
Net::SMTP, but the idea is still the same. OTOH, since it's a pipe, it
may still kick something out into '$@', so it *may* not work as expected.

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Carmel, New York, has an ordinance forbidding men to wear coats
and trousers that don't match.
 
T

Tad McClellan

Experienced but Undocumented said:
Are there any better ways? My mailing list is about 100 people and could
potentially grow to 5-600.


use Mail::Bulkmail;
 
R

Robin

Experienced but Undocumented said:
I'm using the following script which outputs the response from the SMTP
server to the browser. What should I do to make it work silently? Using
PERL 5.6.1 on Redhat Linux 7.3.
Thanks



open(MAIL, "|/usr/sbin/sendmail -bs") or die "Could not launch Mailer";

print MAIL "HELO LONGLOSTFRIEND\n";
print MAIL "MAIL FROM: $mailfrom\n";
print MAIL "$rcpt_to";
print MAIL "DATA\n";
print MAIL "From: $from\n";
print MAIL "Reply-to: $replyto\n";
print MAIL "Bcc:\n";
print MAIL "Subject: $subject\n";
print MAIL "\n";
print MAIL "$message\n";
print MAIL ".\n";
print MAIL "QUIT\n";

close MAIL;

die usually doesn't output to the browser, you have to trap it with an eval
call or something like that. If you want to say:

open(MAIL, "|/usr/sbin/sendmail -bs") or print "Content-Type:text/html\n\n",
"Error, I dunno about die calls yet, and neither does Robin" and exit; #the
output.

That'd probably do what you want to do.
-Robin
 
E

Experienced but Undocumented

Robin said:
die usually doesn't output to the browser, you have to trap it with an eval
call or something like that. If you want to say:

open(MAIL, "|/usr/sbin/sendmail -bs") or print "Content-Type:text/html\n\n",
"Error, I dunno about die calls yet, and neither does Robin" and exit; #the
output.


The script actually isn't dying; it runs, but the browser gets output like
the following, which is what I want to avoid.

220-server ESMTP Exim 4.24 #1 Sun, 25 Apr 2004 14:27:02 -0400
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
250 server Hello user at TEST
250 OK
250 Accepted
354 Enter message, ending with "." on a line by itself
250 OK id=2BHaoLG-00423-Si
221 SERVE closing connection
 
S

Sam Holden

The script actually isn't dying; it runs, but the browser gets output like
the following, which is what I want to avoid.

220-server ESMTP Exim 4.24 #1 Sun, 25 Apr 2004 14:27:02 -0400
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
250 server Hello user at TEST
250 OK
250 Accepted
354 Enter message, ending with "." on a line by itself
250 OK id=2BHaoLG-00423-Si
221 SERVE closing connection

So redirect sendmail's output elsewhere.

Or just use a module which does it all for you.
 
E

Experienced but Undocumented

Experienced but Undocumented said:
I'm using the following script which outputs the response from the SMTP
server to the browser. What should I do to make it work silently? Using
PERL 5.6.1 on Redhat Linux 7.3.
Thanks

open(MAIL, "|/usr/sbin/sendmail -bs") or die "Could not launch Mailer";


Ah!

Since on this server, sendmail is Exim, the -bS commend will work.
 
J

James Willmore

[ ... ]
So redirect sendmail's output elsewhere.

Or just use a module which does it all for you.

I second that :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
It's a damn poor mind that can only think of one way to spell a
word. -- Andrew Jackson
 
J

James Willmore

[ ... ]
So redirect sendmail's output elsewhere.

Or just use a module which does it all for you.

I second that :)

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
It's a damn poor mind that can only think of one way to spell a
word. -- Andrew Jackson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top