Pruning a mailing list to do a mailing in segments

I began with the need to provide a comma delimited list of email addresses to the "bcc" attribute of a <cfmail> tag such that a single invocation of the <cfmail> would occur.

The solution outlined by @gdemaria worked for this issue but a new related issue has arisen. the solution provided resulted in some 13,000 addresses in the "bcc" attribute. This was to much for the size of the virtaul machine on which Smatermail resides.

I now need to process the mailing list in chunks of maybe a thousand records at a time. I'm thinking that I need to loop thru the 13,000 record query to pick up each 1,000 addresses at a time.  I would process the first 1,000 records and then return after some period of time to process the next 1,000 records (maybe a half-hour later.

DOes any one have a suggestion on writing the code to loop thru the initial query to get the 1, 000 record chunk?
Gregory AmbroseAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark GalvinManaging Director / Principal ConsultantCommented:
Hi

For something like that I always use www.mailchimp.com Its great for doing what you have asked and your IP wont get blocked for 'spammer'. There is a free level which may not be enough for what you need but the cost is very low.

And it gives the receiver a more personalised email.

Thanks
Mark
Gregory AmbroseAuthor Commented:
@Mark Galvin

Notwithstanding your good economic advice I still need to develop the code as described in the question. No offense.
gdemariaCommented:
Hi Gregory,
Assuming you have a database table that contains the 13,000 email address you want to mail to, you can add a record or a field in the database to flag when you have sent the email.
Here are two options -
1) More sophisticated - add two tables, one called Mailings and one called MailingAddresses.   The mailings table would have one record for every mailing you want to send out (the name of the mailing, the date to send, description, anything like that).    The MailingAddresses table is populated with all those email addresses that you want to send this particular mailing to.   If your email addresses belong to a user, then the table could be just MailingID, USER_ID, and EmailedDate.    If you don't have a user table (or similar) you could just have  mailingID, emailAddress and EmailedDate.   But I suspect that your email addresses are stored in some time that you can use to whether it is USER_ID or another table...
2) Simple Approach - Add a field on the user table called LastEmailDate (or whatever table holds the email address that you are sending to).  

In either case you have a field that you can populate once an email has been sent to the given user.   This way, you can start and stop your email send anytime you like.   Just fetch the next 100 email addresses where the EmailDate is empty.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Software

From novice to tech pro — start learning today.