I have an application that needs to send out emails. For each email I need to insert custom tracking ids to the URLs in the email message. The HTML content for the email is around 44K and I have tried multiple methods to loop over these records but it eventually crashed the CF server after 4000 or so iterations.
If I try sending the emails immediately CF crashes even faster. I tried storing all of the content in the database putting the complete html code for the emails in a largetext field and that only made MySQL run out of memory as well. I was trying to create the HTML content once and then just swap out the tracking info per user. I thought that would elleviate some stress from the server but it did not improve performance. When I watch the Task Manager in Windows when I start this routine CF memory usage jumps up quickly and in large increments 20K-30K a second.
Basically what I need is for this code to be able to process 50,000+ emails without crashing the server. Suggestions to reduce this apparent memory leak would be greatly appreciated.
<!--- created the intial email with a new variable to swap out --->
<cfset session.emailAddTracking = emailBody>
<!--- create tracking record --->
<cfset temp = mkt.createTrackingRecord(val(marketId),val(getFollowers.prospectId),val(getFollowers.mailid),"email")>
<cfset em.trackingId = "#val(marketId)#-#val(getFollowers.prospectId)#-#val(getFollowers.mailid)#:email">
<cfset em.trackingId = URLencodedFormat(toBase64(em.trackingId))>
<cfset curEmail = getFollowers.email>
<cfset emailBody = replaceNoCase(session.emailAddTracking,"@@@track@@@",em.trackingId,"ALL")>
<cffile action="write" file="D:\temp\mailid_#getFollowers.mailid#_marketid_#marketid#.html" output="#emailBody#">
<!--- add all followers to spool table --->
<cfquery name="addToSpool" datasource="mailspooler">
INSERT INTO mailspool (datecreated, mailid, emailto, emailfrom, emailsubject, marketid)
VALUES (now(), #getFollowers.mailid#, '#curEmail#', '#getSiteDomainPre.systemAdminEmailAddress#', '#getEvents.emailtitle#', #marketid#)