Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Slow exection

Slow exection

Slow exection


when i try to execute the following mail program it takes long to execute (aprox 40-50 sec).Am i following the wrong way advice me

All i need is

i am having an array which contains 6 email ids,I have to send a mail to them

here is the code

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

   open(MAIL,"|$mailprog -t");
   print MAIL "To: $mailarray \n";
   print MAIL "From:$from \n";
   print MAIL "Subject: Test Test \n\n";
   print MAIL "Test\n";
   close (MAIL);

And what changes i have to make if i need to send mail in html format.

Thanks for any help


RE: Slow exection

i'm not sure about sending mail in html format, but

$| is a special variable in perl... it sets buffering.

use another variable name....

most strange characters have special meaning in perl, i'd avoid their use in the future as variable names, because you may be setting something that could be disastrous, without knowing it. anyway, change your variable name, and it will probably improve the speed of your program.

RE: Slow exection

another thing...

you may want to use the foreach loop instead of for.

foreach $mailid (@mailid)


might make for quicker execution.

if your variable in your for loop is an l and not a | disregard my bantering above.

but you might also see some better performance if you set $| = 1;

this removes buffering, so that print prints when executed instead of accumulating in a buffer before being printed.

RE: Slow exection

Thank you lucid dream for your quick reponse,
In the first case iam not using $|, iam using $l;

And Also i tried with $|=1 and foreach loop;

Iam accustomed to use FOR loop(I like FOR loop)
is that foreach loop is faster than for loop

Also I didn't see much difference in the speed.

RE: Slow exection

Send the mail only once, but make each address a blind carbon copy.  Also, you should send the process to the background and send all output to /dev/null.  I'm still researching Perl's forking capabilities to do it that way.

open (MAIL, "| /usr/sbin/sendmail -t >& /dev/null");
print MAIL qq~To: "$title" <$return_addr>\n~;
print MAIL qq~Bcc: ~;

my $address = pop(@LIST);
print MAIL qq~$address~;
foreach $address (@LIST) {print MAIL qq~, $address~;}

print MAIL qq~\nFrom: "$return_name" <$return_addr>\n~;
print MAIL qq~Reply-To: $return_addr\n~;
print MAIL qq~List-Unsubscribe: $return_addr\n~;
print MAIL qq~Subject: $subject\n~;
print MAIL qq~Content-Type: text/plain; charset=us-ascii\n\n~;
print MAIL qq~$body_text\n~;
print MAIL qq~.~;


I think my variables above are fairly self-explanatory.  @LIST is your list to send to, etc.

To send HTML formatted emails, your Content-Type needs to be text/html.

Tom Anderson
CEO, Order amid Chaos, Inc.

RE: Slow exection

Thanks Tom,It worked well,Really iam also think about how to make perl to process in the background.That will make the application so faster at the user end.

Iam struck in between a problem thats what iam not able to get you back immediately.Thanks for your help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close