mail function for batch mails

Posted on 2001-08-02
Last Modified: 2010-03-05
Hi, I have a client that has about 17000 clients on his mailing list. The addresses are all in a mysql table and currently he is attempting to send it all with a php routine, but that causes the mail system to crash as php tries to send all 17000 at one time... Waht I ned is a perl routine that can wait a while after each batch of xxx (what are your suggestions?) and even to keep an eye on the system load and not to send anything unless the system load is below yyy (again, what is a good value?). I would ideally still want to incorporate php in this in parts, maybe to get the addresses from the mysql table and then write them to a text file where perl can read them and then send the mail...
Can someone give me an example of how to do this, it's rather urgent.
Server = linux redhat 7.0 with latest patches etc.
and running sendmail/cyrus
Question by:psimation
  • 2
  • 2
  • 2
  • +3

Expert Comment

ID: 6344687
I can't seem to send out more than 100 at a time without problems.  But my server is a 486

Expert Comment

ID: 6346821
i think u can use same approach in php too. I mean proceess some mails and then some other and soo on.


Expert Comment

ID: 6346900
yeah, but I am kinda interested in what others will say...

I'm sure others do this...

you'd expect to throw sendmail a list of x (memory allowable)
and you'd think it would handle it, in a queue like behaviour.


I would say this is the solution you are looking for...

in other words, if someone can tell you how to create a queue or buffer that will hold all the email vars, and them pass then as sendmail can accept them would be ideal...

like if you could get a value from sendmail as to how many more emails it could handle, or at least how many it had waiting...or even still workable, when it sent the mail and returned to a waiting state.

so, then you could pop off variable sets to sendmail.

I wonder if the amount of data you are passing to sendmail you are passing a big or small message...

just wondering...

of course you can do something like
and loop it.

but that is a hack, right, we need a sendmail xpert here...
cross post a q in the unix area or linux...I don't think there is a sendmail area...if there is...that's the place...

but post a q like "sendmail limits".

Good luck!!!
we all hate these types of problems!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 6347916
usually I use perl programm for such things, but it should work not as CGI script (otherwise timeout errors can happens and so on) but as server side programm. You can call it from CGI script and leave on background, don't wait until it finish work.

So, you should write - usual Perl programm for running from shell, it will send out your mails (use SMTP to send them out - it works nice)
and run.cgi - Perl scripg which calls using
system(' &'). You can add web interface for mail body here

It will a good idea to send a message to yourself in the end of the - to inform you that the programm was successfully finished


Expert Comment

ID: 6376102
 use Mail::Sendmail;

  $hesitate = 0;
  $bulk_message = "this is a test";
  @addresses = ( "", "" );
  foreach $addr ( @addresses ) {
    if ( $hesitate >= 99 ) {
      $hesitate =0;
    else {
       my %mail = (
          To => $addr,
          Subject =>'Bulk Mailing',
          Message => $message );
       sendmail( %mail ) or die $Mail::Sendmail::error;

sub kill_time {
  # do something as simple as wait or
  # as complicated as checking that system is not overburdened...
LVL 17

Author Comment

ID: 6376399
Hi builder
Thanks, your solution is by far the most "complete" so far. I would like to ask you a couple of thing if I may though.
Firstly, as I already mentioned, I already have all the addresses in a mysql table, and since it's easy to (and I already know how to) get those addresses out of the tables and into a file, I would like the perl program to read the list of addresses from a file. I see you create a list @addresses and then fill it by hand, but I would be interested to see how it would look when you pull the addresses from a file and then "populate" the list with whatever is in the file...

Accepted Solution

builder110697 earned 50 total points
ID: 6376426
Not knowing mysql is then my big disadvantage ;-)  I can assume that the query
can be invoked such that the return is an array...  then it is only to rewrite the
script to "talk to" the database...  How 'bout retrieving entries in parcels of 100?

While ( not complete ) {
  get a parcel
  process the addresses
  check to see if the sendmail is complete

Sorry I can't help more,

Expert Comment

ID: 6426466
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:
1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.
2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
3.  Ask Community Support to help split points between participating experts.  Just comment here with details.
4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.
If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.
Hi Experts:
In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.
Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.
Thank you everyone.
Moondancer :)
Community Support Moderator @ Experts Exchange
P.S.  REGARDING POINTS, Question/Answer processes, Grades , Guidelines and more:  
LVL 17

Author Comment

ID: 6426692
I am still far away from being able to say " WOW, it's working, but I have obtained various Perl books, and I believe that with your proposed solution and some imagination, I should come right after all...

Expert Comment

ID: 6426748
In the event you collaborate further and ultimately achieve your goal and wish to change this grade from a B to an A, let me know via comment.

Community Support Moderator @ Experts Exchange

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question