Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delay when calling sendmail

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
Hi,

I don't know if this is a sendmail or perl issue so I will post this question in both forums.

I am trying to send an email from within a perl scrip by calling sendmail, code is below:

$mailprog = '/usr/sbin/sendmail';

open(SENDMAIL, "|$mailprog -t ");
print SENDMAIL "Reply-to: $sender_email\n";
print SENDMAIL "From: $sender_email\n";
print SENDMAIL "Subject: Test\n";
print SENDMAIL "To: me\@anywhere.com\n\n";
print SENDMAIL "$message\n";
close(SENDMAIL);

The problem is that this code takes about a minute to run. If I include this in a loop, then the code takes a minute for each iteration of the loop (ie. each sendmail call). I receive the item once the code has been processed, there is just a long delay to send the item. If I call sendmail from the command line then there is no delay, and I receive the item immediately. (this is what makes me think it has something to do with Perl). I also experience the same delay when calling sendmail from within PHP. Any help would be appreciated.

Thanks...
Rich.
 
This does not sound like a problem with Perl/PHP/Language Of Your Choice. Sounds more like a local configuration error.

If you run sendmail at the command line by hand is it this slow as well?
 
no...that is what confuses me. If I run it by hand from the command line then it is instant. If it was a sendmail configuration then surely this would be delayed also. It is only when I call sendmail from within a script (perl or PHP).
 
Sorry, you said that in the first post and I missed it.

This is a 'work-around' but I always suggest it. Have you tried using Net::SMTP? Its a much more generalized solution and has real debug so you can actually track these problems down.
 
I have not tried using Net::SMTP. I will give it a try...thanks for the info.
 
Sounds like a DNS issue - except that it works from the command line.

Do you get the same error from the command line if you call it the same way as Perl would? (on the end of a pipe I mean)

Do you get the same error calling it in Perl using the system() function?

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
I was thinking DNS as well until I saw the command line thing.

When you call it via the command line are you sending the exact same message?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top