Below, I cut out a routine from a much larger program that builds and throttles 
mail. You should be able to follow the logic. You'll need to adjust for your 
use, but the bottom line is:

1.  put mail addresses in a queue
2. loop and get X records from queue, send them
3. set a time condition 
3. use an if condition to process mail only when the time condition is not the 
current minute and reset the time condition

You should be able to follow the logic. I use the all the time and it works 
flawlessly. You can throttle mail to any rate you want this way. This runs in 
the background so you don't have to wait for processing to finish.

Good Luck,
Robert Harrison

<cfsetting requesttimeout="54000"> 
<cfset send_limit=20> <!--- the number of mails to go out per minute --->
<cfset ntime=#Now()#>
<cfset process=1>

<cfloop condition="#process# eq 1">
    <cfif ntime lte now()>
        <cfset ntime=#DateAdd("n",1,"#ntime#")#>
        <!--- this gets the mail to send this loop from a mail queue previously 
populated,
        that's probably where you are running your CFMAIL --->
        <cfquery name="queued" datasource="#dsn#">
            SELECT TOP #send_limit# *
            FROM tbl_mail_queue
        </cfquery>
    
        <cfif queued.recordcount gte 1>
            <cfloop query="queued">
                <!--- This is the start of processing for each mail --->
                <cfif isEmail(queued.email) is "true">
                    <cfmail to="#trim(queued.email)#"
                        from="#trim(mail_data.sender)#"
                        failto = "#trim(mail_data.bounces)#"
                        subject="#trim(mail_data.subject)#"
                        server="#trim(bulk_smtpid)#"
                        spoolEnable="yes">
                    <!--- YOUR MAIL CONTENT GOES HERE --->
                    </cfmail>
                </cfif>
                    <!--- this is the end of processing for each mail record 
--->
                <!--- clears sent mail from the queue --->
                <cfquery datasource="#dsn#">
                    DELETE From tbl_mail_queue
                    WHERE id=#queued.id#
                </cfquery>
            </cfloop>
        <cfelse>
            <cfset process=0> <!--- stops processing loop --->
            <cfbreak>
        </cfif> <!--- if records found in queue --->
    </cfif><!---  time tag --->
<cfflush>
</cfloop>




  _____  

From: David Long [mailto:d...@northgoods.com]
To: cf-talk [mailto:cf-t...@houseoffusion.com]
Sent: Mon, 24 Aug 2009 17:42:11 -0400
Subject: RE: Throttling CFMail


  Good luck on the throttling. 
  
  I never could get it to work but was able to come to an understanding with
  my Web Host's Sysadmin. Don't know what he did but I now send out 3,000+
  with a single click using:
   <CFLOOP list="#Form.SelectedRecipients#" index="Recipient">
    <CFMAIL 
     from="#Form.Sender#"
     to="#Recipient#"
     subject="#Form.Subject#" 
     type="HTML"
     >
      ***content***
    </CFMAIL>
   </CFLOOP>
  
   and they loop thru the spooler smooth as silk.
  
  One other suggestion, based on sad experience, assuming yours is an "opt-in"
  list, be sure you give subscribers a readily available "unsubscribe" link.
  Many AOL users are too lazy to ask to be removed and will just click the
  "This is spam" button which puts your ISP's server on a blacklist.
  
  Dave
  
  -----Original Message-----
  From: Pete Ruckelshaus [mailto:pruckelsh...@gmail.com] 
  Sent: Monday, August 24, 2009 3:58 PM
  To: cf-talk
  Subject: Throttling CFMail
  
  
  
  I got dinged by my ISP for sending 2,000 email newsletters at once.  Any
  ideas on how to "throttle" these emails so that they are sent in small
  batches, i.e. 100 per minute?  Is there a simple way to accomplish this, or
  do I just need to write my own code that loops through and sends emails
  incrementally?
  Thanks.
  
  Pete
  
  
  
  
  

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:325649
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to