SendMail Problem

J

jim

Hello,

I am having a problem w/SendMail reporting: "No recipient addresses
found in header".

Funny thing is though, I properly recieve the email message.

What do I need to change to stop recieving the error message in my
browser?

Thanks for your help.

-jim



Here is the code:


sub my_send_mail
{
local($fromuser, $touser, $subject, $messagebody) = @_;

local($old_path) = $ENV{"PATH"};


$ENV{"PATH"} = "";
$ENV{ENV} = "";

open(SENDMAIL, "| /bin/sendmail -t -n") || &web_error ("Unable to open
sendmail");

$ENV{"PATH"} = $old_path;

print SENDMAIL "To: $touser\n";
print SENDMAIL "From: $fromuser\n";
print SENDMAIL "Subject: $subject\n\n";
print SENDMAIL "$messagebody\n";
close(SENDMAIL);

}
 
T

Tad McClellan

I am having a problem w/SendMail


I can't help with that part, other than checking for
newlines in the arguments.

sub my_send_mail
{
local($fromuser, $touser, $subject, $messagebody) = @_;


You should always prefer lexical (my) variables over dynamic (local)
variables, except when you can't.


my($fromuser, $touser, $subject, $messagebody) = @_;

die "newlines in address" if grep /\n/, $fromuser, $touser;

local($old_path) = $ENV{"PATH"};
$ENV{"PATH"} = "";
$ENV{ENV} = "";


Why are you changing environment variables?

Do you have taint checking turned on or something?

close(SENDMAIL);


You should be checking the return value from close() as well
as from open().
 
G

Gunnar Hjalmarsson

jim said:
I am having a problem w/SendMail reporting: "No recipient addresses
found in header".

Funny thing is though, I properly recieve the email message.

What do I need to change to stop recieving the error message in my
browser?

Don't know. Whatever the reason is, it has probably nothing to do with
the part of the code you posted.
 
J

jim

Hey,
I can't help with that part, other than checking for
Well, that was it.
Thank you for the input.


Now the weird part is that I am receiving two email messages.
I am only sending one. Very strange.

You should always prefer lexical (my) variables over dynamic (local)
variables, except when you can't.
Yep, you certainly are correct. <lame excuse>...Long story.... Legacy
code I inherited... Under time pressure to be done w/this project.</lame
excuse>

my($fromuser, $touser, $subject, $messagebody) = @_;
die "newlines in address" if grep /\n/, $fromuser, $touser;
Made changes to code.
$ENV{ENV} = "";
Do you have taint checking turned on or something?
Yes.
 
J

James Willmore

I am having a problem w/SendMail reporting: "No recipient addresses
found in header".

Funny thing is though, I properly recieve the email message.

What do I need to change to stop recieving the error message in my
browser?
<snip>

Have you considered using the many email modules available in Perl?

I know this doesn't directly answer your question, but I find this a
rather poor way to send email. It's not portable and relies upon
_you_ to check for errors, know how to pass parameters to the
executing application (in this case, sendmail), and it makes for a
nightmare for maintainence. But, that's all just my opinion :)

--
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 ...
Twenty Percent of Zero is Better than Nothing. -- Walt Kelly
 
J

jim

James,
Have you considered using the many email modules available in Perl?
I know this doesn't directly answer your question, but I find this a
No, have not considered this. I am an experienced programmer, but very new
to Perl. I am just trying to get code working that I was given, so I have
tended to look at the leafs, not the forest.

Suggestions?

Thanks for the info.

-jim
 
D

David Efflandt

Hey,

Well, that was it.
Thank you for the input.


Now the weird part is that I am receiving two email messages.
I am only sending one. Very strange.

I suspect your $touser is not formatted properly. Is it in single or
double quotes? If in double quotes, did you escape the @? Does it
contain anything other than e-mail address (real name)?
 
J

James Willmore

James,

No, have not considered this. I am an experienced programmer, but
very new to Perl. I am just trying to get code working that I was
given, so I have tended to look at the leafs, not the forest.

Suggestions?

Net::SMTP is a good one. So is MIME::Lite.
Mail::Mailer, if I not mistaken, comes with the standard with Perl.

Visit http://search.cpan.org/ . There, you can search for email
modules and read the documentation before using the modules - which is
something I highly recommend before using them; or even installing
them. If I can follow the documentation _before_ installing the
module, then chances are I can use the module successfully.

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 ...
What I tell you three times is true.
 
A

Andrew Rich \(VK4TEC\)

#!/usr/bin/perl
use Net::SMTP;
$from = '(e-mail address removed)';
$to = '(e-mail address removed)';
$subject = 'Updated web site';
$smtp = Net::SMTP->new('smtp.dogo.com.au',Debug=>0);
$smtp->mail($email);
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$smtp->datasend("From: $email\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("Date: Sun, 12 Oct 2003 10:55:55 -0500\n");
$smtp->datasend("www.software.net\n");
$smtp->dataend();
sleep 5;
print "$email\n";
$smtp->quit;
 

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

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top