<%@LANGUAGE="VBSCRIPT"%> <% '============================================================= ' Spd E-Letter v4.0 Automated Broadcast & Scheduled Emailer ' Copyright (c) 2001-2002 PensaWorks, Inc. ' All rights reserved. '============================================================= if request("showError") = "Y" then on error goto 0 else on error resume next end if response.buffer = true server.scriptTimeout = 500000 thisPage = "automated_tasks.asp" SendMailer = MailerProgram lastRun = LastAutomatedRunDate if lastRun = "" then lastRun = getNumFromDate(Now) else if NOT IsNumeric(lastRun) then lastRun = getNumFromDate(Now) end if end if lastRunDate = getDateFromNum(lastRun) thisRunDate = now prfUnsubscribe = ActionURL & "?a=u" if (request("a") <> "") then action = request("a") else action = "start" if (IsNumeric(request("m")) AND request("m") <> "") then msgID = CLng(request("m")) else msgID = 0 if (IsNumeric(request("t")) AND request("t") <> "") then tempID = CLng(request("t")) else tempID = 0 if action = "start" then data = data & "Spd E-Letter Automated Broadcasting System Starting on " & Now & "

" mlConn.Execute("INSERT INTO ML_Temp (tempType, tempDate, tempData) VALUES (1," & cfgDate & ",'" & replace(data, "'", "''") & "')") set getTempID = mlConn.Execute("SELECT * FROM ML_Temp WHERE TempType = 1 AND tempDate = " & cfgDate) if getTempID.EOF then tempID = 0 else tempID = getTempID("tempID") end if set getTempID = nothing action = "auto" mlConn.Execute("UPDATE ML_Broadcast SET Status = 'Broadcasting' WHERE MessageType = 'S'") else end if doIt = auto() doIt = sched() data = data & "
Automated Broadcasting System Ended on " & Now & "" doIt = updateTemp2(tempID, data) set getData = mlConn.Execute("SELECT * FROM ML_Temp WHERE tempID = " & tempID) if getData.EOF then response.write "Error: Could not find data." else response.write getData("tempData") end if set getData = nothing mlConn.Execute("UPDATE ML_Prefs SET LastAutomatedRunDate = " & cfgDate) function updateTemp(msgID, tempID, data, action, extras) set getData = mlConn.Execute("SELECT * FROM ML_Temp WHERE tempID = " & tempID) if (getData.EOF) then tempData = "" else tempData = getData("tempData") set getData = nothing tempData = tempData + data mlConn.Execute("UPDATE ML_Temp SET tempData = '" & replace(tempData, "'", "''") & "' WHERE tempID = " & tempID) end function function updateTemp2(tempID, data) set getData = mlConn.Execute("SELECT * FROM ML_Temp WHERE tempID = " & tempID) if (getData.EOF) then tempData = "" else tempData = getData("tempData") set getData = nothing tempData = tempData + data mlConn.Execute("UPDATE ML_Temp SET tempData = '" & replace(tempData, "'", "''") & "' WHERE tempID = " & tempID) end function function auto() set getRecords = mlConn.Execute("SELECT * FROM ML_Broadcast WHERE Status = 'Broadcasting' AND MessageType = 'S'") if getRecords.EOF then set getRecords = nothing data = "
Finished running the Automated Emails on " & Now & ".


" doIt = updateTemp(0, tempID, data, "sched", "") else while NOT getRecords.EOF msgID = clng(getRecords("MessageID")) doIt = auto1(msgID) getRecords.movenext() wend set getRecords = nothing data = "
Finished running the Automated Emails on " & Now & ".


" doIt = updateTemp(0, tempID, data, "sched", "") end if end function function auto1(msgID) if (NOT IsNumeric(msgID)) then msgID = 0 set getMessage = mlConn.Execute("SELECT * FROM ML_Broadcast WHERE MessageID = " & msgID) if getMessage.EOF then set getMessage = nothing data = "Error: Could not find the Automated Email with an ID of " & msgID & ".
" doIt = updateTemp(0, tempID, data, "auto", extras) else msgListID = getMessage("ListID") msgSubject = getMessage("Subject") msgNumDays = getMessage("NumDays") msgLastRun = msgBroadcastedDate msgThisTime = Now if msgLastRun = "" then msgLastRunDate = DateAdd("d", -1, Now) elseif msgLastRun = 0 then msgLastRunDate = DateAdd("d", -1, Now) else msgLastRunDate = getDateFromNum(msgLastRun) end if timeElapsed = dateDiff("s", lastRunDate, thisRunDate) if timeElapsed > 86400 then timeElapsed = 86400 end if msgHighDate = DateAdd("d", -msgNumDays, thisRunDate) msgHighNum = getNumFromDate(msgHighDate) msgLowDate = DateAdd("s", -timeElapsed, msgHighDate) msgLowNum = getNumFromDate(msgLowDate) strSQL = "SELECT * FROM ML_Subscribers INNER JOIN ML_Lists ON ML_Subscribers.ListID = ML_Lists.ListID WHERE ML_Subscribers.SubscribedDate <= " & msgHighNum & " AND ML_Subscribers.SubscribedDate >= " & msgLowNum & " AND subRemoved <> 1 AND ML_Subscribers.ListID = " & msgListID & " ORDER BY ML_Subscribers.SubscriberID ASC" msgType = 1 doIt = sendNewsletter(msgID, msgType, strSQL, "auto", subscriberTotal) mlConn.Execute("UPDATE ML_Broadcast SET Status = 'Broadcasted', msgBroadcastedDate = " & cfgDate & " WHERE MessageID = " & msgID) set getMessage = nothing data = "Finished Broadcasting Automated Email '" & msgSubject & "' to " & subscriberTotal & " subscribers.
" doIt = updateTemp(0, tempID, data, "auto", "") end if end function function sched() thisDate = getNumFromDate(Now) set getRecords = mlConn.Execute("SELECT * FROM ML_Broadcast WHERE Status = 'Pending' AND MessageType = 'R' AND sch = 1 AND msgSchDate <= " & thisDate) if getRecords.EOF then set getRecords = nothing data = "
Finished running the Scheduled Newsletters on " & Now & ".


" doIt = updateTemp(0, tempID, data, "sched", "") else while NOT getRecords.EOF msgID = clng(getRecords("MessageID")) doIt = sched1(msgID) getRecords.movenext() wend set getRecords = nothing data = "
Finished running the Scheduled Newsletters on " & Now & ".


" doIt = updateTemp(0, tempID, data, "finish", "") end if end function function sched1(msgID) if (NOT IsNumeric(msgID)) then msgID = 0 set getMessage = mlConn.Execute("SELECT * FROM ML_Broadcast WHERE MessageID = " & msgID) if getMessage.EOF then set getMessage = nothing data = "Error: Could not find the Scheduled Newsletter with an ID of " & msgID & ".
" doIt = updateTemp(0, tempID, data, "sched", extras) else msgSubject = getMessage("Subject") msgType = 2 doIt = sendNewsletter(msgID, msgType, strSQL, "sched", subscriberTotal) mlConn.Execute("UPDATE ML_Broadcast SET Status = 'Broadcasted', msgBroadcastedDate = " & cfgDate & " WHERE MessageID = " & msgID) set getMessage = nothing data = "Finished Broadcasting the Scheduled Newsletter '" & msgSubject & "' to " & subscriberTotal & " subscribers.
" doIt = updateTemp(0, tempID, data, "finish", "") end if end function function sendNewsletter(msgID, msgType, msgSQL, action, subscriberTotal) subscriberTotal = 0 prfUnsubscribe = ActionURL & "?a=u" if (isNumeric(BroadcastNum)) then sendPerPage = cint(BroadcastNum) else sendPerPage = 100 onNum = 0 : msgTextHeader = "" : msgTextFooter = "" : msgHTMLHeader = "" : msgHTMLFooter = "" : msgText = "" : msgHTML = "" mlConn.Execute("UPDATE ML_Broadcast SET msgActualRecipients = 0 WHERE msgActualRecipients IS NULL") mlConn.Execute("UPDATE ML_Broadcast SET BroadcastSubscribers = 0 WHERE BroadcastSubscribers IS NULL") set msgRecord = Server.CreateObject("ADODB.Recordset") msgRecord.ActiveConnection = mlConn msgRecord.Source = "SELECT ML_Broadcast.ListID AS msgListID, * FROM ML_Broadcast INNER JOIN ML_Lists ON ML_Broadcast.ListID = ML_Lists.ListID WHERE ML_Broadcast.MessageID = " & msgID msgRecord.CursorType = 3 msgRecord.Open() if (msgRecord.EOF) then data = "Error: Could not find Newsletter Data with an ID of " & msgID & ".
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if if msgRecord("msgIncludeTemplateText") = 1 then msgTextHeader = msgRecord("HeaderText") : msgTextFooter = msgRecord("FooterText") end if if msgRecord("msgIncludeTemplateHTML") = 1 then msgHTMLHeader = msgRecord("HeaderHTML") : msgHTMLFooter = msgRecord("FooterHTML") end if msgStatus = msgRecord("Status") if (msgStatus = "Broadcasted") then data = "Error: This Newsletter has already been broadcasted (" & msgID & ").
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if msgListID = msgRecord("msgListID") msgListName = msgRecord("ListName") msgFormat = msgRecord("msgFormat") msgSubject = msgRecord("Subject") msgFromName = msgRecord("FromName") msgFromEmail = msgRecord("FromEmail") msgReplyTo = msgRecord("ReplyTo") msgPriority = msgRecord("MessagePriority") if lcase(useMailer) = "cdomail" or lcase(SendMailer) = "chilimail" then if msgPriority = 5 then msgPriority = 0 elseif msgPriority = 3 then msgPriority = 1 elseif msgPriority = 1 then msgPriority = 2 end if end if msgSource = msgRecord("msgSource") if msgSource = 1 then msgText = msgRecord("TextMessage") msgHTML = msgRecord("HTMLMessage") elseif msgSource = 2 then msgSourceFileText = msgRecord("msgSourceFileText") msgSourceFileHTML = msgRecord("msgSourceFileHTML") if msgFormat = 1 or msgFormat = 2 then if doesFileExist(msgSourceFileText) then fileData = readFileData(msgSourceFileText, fileResponse) if NOT fileResponse then data = "Error: Could not read the text file for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function else msgText = fileData end if else data = "Error: Could not read the text file for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if end if if msgFormat = 1 or msgFormat = 3 then if doesFileExist(msgSourceFileHTML) then fileData = readFileData(msgSourceFileHTML, fileResponse) if NOT fileResponse then data = "Error: Could not read the URL for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function else msgHTML = fileData end if else data = "Error: Could not read the URL for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if end if elseif msgSource = 3 then msgSourceURLText = msgRecord("msgSourceURLText") msgSourceURLHTML = msgRecord("msgSourceURLHTML") msgSourceTextTimes = msgRecord("msgSourceTextTimes") msgSourceHTMLTimes = msgRecord("msgSourceHTMLTimes") if msgFormat = 1 or msgFormat = 2 then msgText = getNewsletterData("Text", 0, "email@domain.com", "True", msgSourceURLText, bitResponse) if (NOT bitResponse) then data = "Error: Could not read the URL for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if end if if msgFormat = 1 or msgFormat = 3 then msgHTML = getNewsletterData("HTML", 0, "email@domain.com", "True", msgSourceURLHTML, bitResponse) if (NOT bitResponse) then data = "Error: Could not read the URL for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if end if else data = "Error: Could not read the URL for the newsletter with an ID of " & msgID & "
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if msgText = msgTextHeader & msgText & msgTextFooter msgHTML = msgHTMLHeader & msgHTML & msgHTMLFooter msgTextSnippets = parseSnippets(msgText, 1) msgHTMLSnippets = parseSnippets(msgHTML, 1) trackLinks = parseTextURLTracking(msgText, msgHTML, msgID) msgUseSQL = msgRecord("msgUseSQL") msgSQLStr = msgRecord("msgSQLStr") if msgType = 1 then SQL = msgSQL else if msgUseSQL = 2 then SQL = msgSQLStr else SQL = "SELECT * FROM ML_Subscribers WHERE subRemoved <> 1" &_ " AND numClicks >= " & msgRecord("msgLowClicksF") & " AND numClicks <= " & msgRecord("msgHighClicksF") &_ " AND SubscribedDate >= " & msgRecord("msgSinceDateF") & " AND SubscribedDate <= " & msgRecord("msgToDateF") &_ " AND numReads >= " & msgRecord("msgLowReadsF") & " AND numReads <= " & msgRecord("msgHighReadsF") &_ " AND ListID = " & msgListID &_ " ORDER BY ML_Subscribers.SubscriberID ASC" end if end if set usrRecord = server.createobject("ADODB.Recordset") usrRecord.activeconnection = mlConn usrRecord.source = SQL usrRecord.cursortype = 3 usrRecord.open() if (usrRecord.EOF) then data = "NOTE: No Subscribers Found for the newsletter with an ID of " & msgID & ".
" doIt = updateTemp(0, tempID, data, action, extras) exit function end if sendTotal = usrRecord.recordcount msgOnSubscriberID = msgRecord("msgOnSubscriberID") msgTotalSubscribers = msgRecord("msgTotalSubscribers") msgActualRecipients = msgRecord("msgActualRecipients") if msgRecord("BroadcastSubscribers") = 0 or isnull(msgRecord("BroadcastSubscribers")) then usrIndex = 1 msgOnSubscriberID = 0 mlConn.execute("UPDATE ML_Broadcast SET msgBroadcastBegun = " & cfgDate & ", Status = 'Broadcasting' WHERE MessageID = " & msgID) else usrIndex = msgRecord("BroadcastSubscribers") msgOnSubscriberID = msgRecord("msgOnSubscriberID") end if if lcase(right(sql, 41)) = " order by ml_subscribers.subscriberid asc" then if (not isnumeric(msgOnSubscriberID)) then msgOnSubscriberID = 0 while (usrRecord("SubscriberID") < msgOnSubscriberID) usrRecord.movenext wend else usrRecord.move usrIndex - 1 end if err.clear sendPerPage = 100000000 while (onNum < sendPerPage) AND (NOT usrRecord.EOF) onNum = onNum + 1 if msgFormat = 3 then emlFormatText = "HTML" emlFormatInt = 0 emlFormatType = "text/html" elseif msgFormat = 2 then emlFormatText = "Text" emlFormatInt = 1 emlFormatType = "text/plain" else if lcase(left(usrRecord("Format"),1)) = "h" then emlFormatText = "HTML" emlFormatInt = 0 emlFormatType = "text/html" else emlFormatText = "Text" emlFormatInt = 1 emlFormatType = "text/plain" end if end if if msgSource = 3 then if emlFormatText = "HTML" then if msgSourceHTMLTimes = 2 then tempMessage = getNewsletterData("HTML", usrRecord("SubscriberID"), usrRecord("Email"), "False", msgSourceURLHTML, bitResponse) if (NOT bitResponse) then emlSend = false else if lcase(tempMessage) = "skip" then emlSend = false else msgTextSnippets = parseSnippets(tempMessage, 1) emlMessageTemp = parseTextURLTracking(tempMessage, "", msgID) emlMessage = msgHTMLHeader & tempMessage & msgHTMLFooter msgTextSnippets = parseSnippets(emlMessage, 1) emlSend = true end if end if else emlMessage = msgHTML emlSend = true end if else if msgSourceTextTimes = 2 then tempMessage = getNewsletterData("Text", usrRecord("SubscriberID"), usrRecord("Email"), "False", msgSourceURLText, bitResponse) if (NOT bitResponse) then emlSend = false else if lcase(tempMessage) = "skip" then emlSend = false else msgTextSnippets = parseSnippets(tempMessage, 1) emlMessageTemp = parseTextURLTracking("", tempMessage, msgID) emlMessage = msgTextHeader & tempMessage & msgTextFooter msgTextSnippets = parseSnippets(emlMessage, 1) emlSend = true end if end if else emlMessage = msgText msgTextSnippets = parseSnippets(emlMessage, 1) emlSend = true end if end if else if emlFormatInt = 0 then emlMessage = msgHTML emlSend = true else emlMessage = msgText emlSend = true end if end if emlSubject = msgSubject if emlSend then emlSubject = customizeIt(emlSubject, usrRecord) emlMessage = customizeIt(emlMessage, usrRecord) sendIt = sendEmail(usrRecord, usrIndex, SendMailer, msgFromName, msgFromEmail, MailerPath, PortNum, emlFormatText, emlFormatType, emlFormatInt, msgReplyTo, emlSubject, emlMessage, msgPriority) updateSQL = "UPDATE ML_Broadcast SET BroadcastSubscribers = (BroadcastSubscribers + 1), msgBroadcastedDate = " & getNumFromDate(Now) & ", msgOnSubscriberID = " & usrRecord("SubscriberID") & ", msgActualRecipients = (msgActualRecipients + 1) WHERE MessageID = " & msgID else updateSQL = "UPDATE ML_Broadcast SET BroadcastSubscribers = (BroadcastSubscribers + 1), msgBroadcastedDate = " & getNumFromDate(Now) & ", msgOnSubscriberID = " & usrRecord("SubscriberID") & " WHERE MessageID = " & msgID end if mlConn.execute(updateSQL) usrRecord.movenext usrIndex = usrIndex + 1 msgFormatInt = "" wend if usrRecord.EOF then endOfBroadcast = finished(usrIndex, cfgDate, msgID, msgListID) end if subscriberTotal = (usrIndex - 1) if (subscriberTotal < 1) then subscriberTotal = 0 end function function sendEmail(obj, usrIndex, SendMailer, msgFromName, msgFromEmail, MailerPath, PortNum, emlFormatText, emlFormatType, emlFormatInt, msgReplyTo, emlSubject, emlMessage, msgPriority) select case SendMailer case "ASPMail", "ASPQMail" set Mailer = Server.CreateObject("SMTPsvg.Mailer") Mailer.RemoteHost = MailerPath Mailer.ContentType = emlFormatType Mailer.FromName = msgFromName Mailer.FromAddress = msgFromEmail Mailer.ReplyTo = msgReplyTo Mailer.AddRecipient obj("Name"), obj("Email") Mailer.Subject = emlSubject Mailer.BodyText = emlMessage Mailer.Priority = msgPriority if SendMailer = "ASPQMail" then Mailer.QMessage = true end if Mailer.SendMail case "ASPEmail" Set Mailer = Server.CreateObject("Persits.MailSender") Mailer.Host = MailerPath Mailer.From = msgFrom Mailer.FromName = msgFromName Mailer.AddReplyTo(msgReplyTo) Mailer.Priority = msgPriority Mailer.AddAddress obj("Email"), obj("Name") Mailer.Subject = emlSubject if lcase(emlFormatText) = "text" then Mailer.IsHTML = false else Mailer.IsHTML = true end if Mailer.Body = emlMessage Mailer.Send case "JMail" Set Mailer = Server.CreateObject("JMail.SMTPMail") Mailer.ServerAddress = MailerPath & ":" & PortNum Mailer.ContentType = emlFormatType Mailer.AddRecipient obj("Email") Mailer.Sender = msgFromEmail Mailer.ReplyTo = msgReplyTo Mailer.Subject = emlSubject Mailer.Body = emlMessage Mailer.Execute case "SA-SmtpMail" set Mailer = Server.CreateObject("SoftArtisans.SMTPMail") Mailer.RemoteHost = MailerPath Mailer.contenttype = emlFormatType Mailer.AddRecipient obj("Name"), obj("Email") Mailer.FromName = msgFromName Mailer.FromAddress = msgFromEmail Mailer.ReplyTo = msgReplyTo Mailer.Subject = emlSubject Mailer.BodyText = emlMessage Mailer.SendMail case else set Mailer = Server.CreateObject("CDONTS.NewMail") Mailer.MailFormat = emlFormatInt Mailer.BodyFormat = emlFormatInt Mailer.To = obj("Name") & " <" & obj("Email") & ">" Mailer.From = msgFromName & " <" & msgFromEmail & ">" Mailer.Subject = emlSubject Mailer.Body = emlMessage Mailer.Send end select end function function finished(usrIndex, cfgDate, msgID, msgListID) mlConn.execute("UPDATE ML_URLs SET urlSends = " & usrIndex & " WHERE MessageID = " & msgID) mlConn.execute("UPDATE ML_Broadcast SET Status = 'Broadcasted', msgBroadcastedDate = " & cfgDate & ", BroadcastedBy = 'Automated Script' WHERE MessageID = " & msgID) mlConn.execute("UPDATE ML_Lists SET LastEmailSentDate = " & cfgDate & " WHERE ListID = " & msgListID) end function function customizeIt(data, obj) data = replace(data, "#newsletterid#", "" & msgID, 1, -1, 1) data = replace(data, "#name#", "" & obj("Name"), 1, -1, 1) data = replace(data, "#email#", "" & obj("Email"), 1, -1, 1) data = replace(data, "#subscribed#", "" & getDateFromNum(obj("SubscribedDate")), 1, -1, 1) data = replace(data, "#format#", "" & obj("Format"), 1, -1, 1) data = replace(data, "#subscriberid#", "" & obj("SubscriberID"), 1, -1, 1) data = replace(data, "#shortdate#", formatdatetime(now, 2), 1, -1, 1) data = replace(data, "#longdate#", formatdatetime(now, 1), 1, -1, 1) data = replace(data, "#listname#", "" & msgListName, 1, -1, 1) data = replace(data, "#numbersubscribers#", "" & NumSubscribers, 1, -1, 1) data = replace(data, "#trackreads#", "", 1, -1, 1) nameArr = split(obj("Name"), " ", -1, 1) if (UBound(nameArr) >= 0) then fname = nameArr(0) data = replace(data, "#firstname#", fname, 1, -1, 1) if instr(1, data, "#unsubscribe#", 1) then code = 1 encode = obj("Email") for idxChar = 1 to len(encode) code = code * asc(mid(encode, idxChar, 1)) mod 11111 next code = code mod 10000 data = replace(data, "#unsubscribe#", prfUnsubscribe & "&i=" & obj("SubscriberID") & "&c=" & code & "&m=" & msgID, 1, -1, 1) end if data = replaceData(obj, data) customizeIt = data end function function parseTextURLTracking(msgText, msgHTML, msgID) urlText = 0 do while instr(1, msgText, "[/url]", 1) > instr(1, msgText, "[url]", 1) and instr(1, msgText, "[url]", 1) > 0 urlText = urlText + 1 urlStart = instr(1, msgText, "[url]", 1) + 5 urlEnd = instr(urlStart, msgText, "[/url]", 1) urlRedirect = mid(msgText, urlStart, urlEnd - urlStart) set urlRecord = Server.CreateObject("ADODB.Recordset") urlRecord.ActiveConnection = mlConn urlRecord.Source = "SELECT * FROM ML_URLs WHERE urlInside = 0 AND MessageID = " & msgID & " AND urlIndex = " & urlText & " ORDER BY urlID DESC" urlRecord.CursorType = 3 urlRecord.Open() if urlRecord.eof then mlConn.execute("INSERT INTO ML_URLs (MessageID, urlRedirect, urlIndex, urlInside, urlClicks) VALUES (" & msgID & ", '" & replace(urlRedirect, "'", "''") & "', " & urlText & ", 0, 0)") set urlRecord = Server.CreateObject("ADODB.Recordset") urlRecord.ActiveConnection = mlConn urlRecord.Source = "SELECT * FROM ML_URLs WHERE urlInside = 0 AND MessageID = " & msgID & " AND urlIndex = " & urlText & " ORDER BY urlID DESC" urlRecord.CursorType = 3 urlRecord.Open() end if msgText = replace(msgText, "[url]" & urlRedirect & "[/url]", RedirectURL & "?i=#subscriberid#&l=" & urlRecord("urlID"), 1, -1, 1) loop if instr(1, msgText, "[/url]", 1) > 0 or instr(1, msgText, "[url]", 1) > 0 then response.write " Broadcast Error: Parsing failed. Please correct Text message URL's and try again.
" end if urlHTML = 0 do while instr(1, msgHTML, "[/url]", 1) > instr(1, msgHTML, "[url]", 1) and instr(1, msgHTML, "[url]", 1) > 0 urlHTML = urlHTML + 1 urlStart = instr(1, msgHTML, "[url]", 1) + 5 urlEnd = instr(urlStart, msgHTML, "[/url]", 1) urlRedirect = mid(msgHTML, urlStart, urlEnd - urlStart) set urlRecord = Server.CreateObject("ADODB.Recordset") urlRecord.ActiveConnection = mlConn urlRecord.Source = "SELECT * FROM ML_URLs WHERE urlInside = 1 AND MessageID = " & msgID & " AND urlIndex = " & urlHTML & " ORDER BY urlID DESC" urlRecord.CursorType = 3 urlRecord.Open() if urlRecord.eof then mlConn.execute("INSERT INTO ML_URLs (MessageID, urlRedirect, urlIndex, urlInside, urlClicks) VALUES (" & msgID & ", '" & replace(urlRedirect, "'", "''") & "', " & urlHTML & ", 1, 0)") set urlRecord = Server.CreateObject("ADODB.Recordset") urlRecord.ActiveConnection = mlConn urlRecord.Source = "SELECT * FROM ML_URLs WHERE urlInside = 1 AND MessageID = " & msgID & " AND urlIndex = " & urlHTML & " ORDER BY urlID DESC" urlRecord.CursorType = 3 urlRecord.Open() end if msgHTML = replace(msgHTML, "[url]" & urlRedirect & "[/url]", RedirectURL & "?i=#subscriberid#&l=" & urlRecord("urlID"), 1, -1, 1) loop if instr(1, msgHTML, "[/url]", 1) > 0 or instr(1, msgHTML, "[url]", 1) > 0 then response.write "Broadcast Error: Parsing failed. Please correct HTML message URL's and try again.
" end if urlTotal = urlHTML + urlText mlConn.execute("UPDATE ML_Broadcast SET BroadcastURLs = " & urlTotal & " WHERE MessageID = " & msgID) end function %>