Skip to main content
January 31, 2010
Question

Sending emails with 2 minute interval

  • January 31, 2010
  • 1 reply
  • 2130 views

Hi all,

I am really scratching my head on this.  I am trying to write a method that sends out 500 emails at a time with 2 minute interval between each group of 500 emails.  My first attempt is to write a recursive function that calls itself after  2 minute intervals.  However, at the beginning of the second iteration, where I do cfquery to get list of emails,  I would get "The request has exceeded the allowable time limit Tag:CFQuery". 

I am not sure why the time-out because i am doing a fresh cfquery.  If I lower the interval to 10 seconds, the function works okay.   But I need it to be 2 minutes to conform to the host company's policy.  I have also tried doing it in a simple cfloop, but faced with the same error.

How do I fix this?

Assume 1000 email addresses, so 2 iteration only.  Using MS SQL server.

<cffunction name="sendEmails">
     <cfargument name="loopIdx">
     <cfargument name="totalLoopNum" default="2">

     <!--- get email addresses --->
     <cfquery name="getEmails_qr">
       select top 500 emails
       from emailList
       <cfif arguments.loopIdx gt 1>
          where emails not in (select top #(idx-1)*500# emails from emailList order by emailNum)
       </cfif>
       order by emailNum
     </cfquery>

     <!--- send out emails now --->
     <cfoutput query="getEmails_qr"><cfmail> ... </cfmail></cfoutput>

     <cfif arguments.loopIdx lt arguments.totalLoopNum>
          <!--- sleep for 2 minutes then calls itself --->
          <cfscript>
               interval = 120;
               thread = createObject("java", "java.lang.Thread");
               thread.sleep(javaCast("long", 1000*interval));
           </cfscript>

           <cfset sendEmails(arguments.loopIdx+1, arguments.totalLoopNum)>

     </cfif>

</cffunction>

    This topic has been closed for replies.

    1 reply

    Inspiring
    January 31, 2010

    Did you google the error message?  I suspect not.  This hould always be your first troubleshooting step when you get an error you're not familiar with.

    CF can be set to kill any request that takes longer than some arbitrary period of time.  This is a setting in CFAdmin.  Your request is taking longer than the setting in CFAdmin.

    You can increase this timeout on a request-by-request basis by using the <cfsetting> tag.

    --

    Adam

    Owainnorth
    Inspiring
    February 1, 2010

    As someone who works for a hosting company, do bear in mind that their rules will be in place for good reason.

    Web servers aren't really made for mass-mailing of thousands of mails in one go - you're also running the risk that some other site on the server may be doing the same, will get it blacklisted somewhere and your mails will suddenly all start failing.

    Not a dig or anything, but expect to have to possibly get your own SMTP server at some point of you're needing to send out thousands of mails rather than just working around their controls.

    O.