tags:

views:

47

answers:

3

What is the alternate logic to Iterate other than "for" loop in sending newsletter to many users as this will exceed maximum time execution time.

+2  A: 

Instead of using one instance of your program to send N mails, with N being the total amount of mails to send, you could use several instances of a program, which will each send a small number of mails -- and launch that program as many times as needed.

What I mean is instead of having 1 program that is launched once and sends 1000 mails, you'd have one program that sends 100 mails, but you'd launch it 10 times.


The difficulty is that you have to :

  • Keep track of which mails were already sent, to not send a mail to the same use twice
    • This can be done sending mails to the users 1 to 100 the first time, 101 to 200 the second time, 201 to 300 the third time, ...
  • Relaunch the program until it doesn't send mails anymore
    • i.e. use some loop that detects how many mails were sent -- and if some were sent, relaunch the program so it does the next "page" of users
Pascal MARTIN
Exactly. If you don't have enough time to send them one at a time in a loop, you are going to have to send more than one at a time.
CaptnCraig
+1  A: 

Not sure what technology you're using, but one thing you could try is a queue data structure with multiple threads responsible for sending messages. You could have one thread feeding email addresses/addresses (or whatever contact info) into the queue, then have multiple threads pulling messages off the queue to send. You'll probably want to use some sort of synchronization for the consumer threads, so that each contact is only used a single time.

The "producer" thread (the one feeding the addresses into the queue) might be able to just dump the entire user set into the queue at once, or you may need to do it more gradually (e.g. 100 at a time), if memory becomes an issue.

Andy White
A: 

Any email library or client worth anything should allow you to send a message to multiple recipients.

CaptnCraig