Tuesday, September 30, 2008

Automatically send out emails, 50 mails per cycle


<script type="text/javascript">
/**
*@description pause( iMilliseconds ) Cause the single Javascript thread to hald/pause/sleep/wait for a specified period of time, by opening in modalDialog window (IE only) that modally locks the browser until it returns. This modal dialog is not opened to any page, but uses the Javascript: protocol to execute a javascript setTimeout. In this modal context the setTimeout, has the desired affect of preventing any other script execution. The sole purpose of the timeout execution script is to close the modal dialog which will return control/unluck the browser. The intention was to find a way to allow the UI to be updated and rendered in the middle of function/method without the need to split the method up, remove nested calls, or use closures. Used in this fashion to update the UI, a 0 (zero) is usually passed (or optionally omitted altogether) so that the only delay is for the UI to render.
*@version Note Please be aware that the user interface WILL update its rendering (if you've made and DOM/CSS/Text changes they will appear) and this may significantly slow down program execution if looping.
*@keywords pause sleep wait halt javascript show modal dialog set timeout multi-threaded single thread
*@version 1.2
* @param {Object} iMilliseconds [optional] the number of milliseconds the code will pause before returning - If no value is passed the code will returned immediately (as if a 0 were passed)
* @return undefined there is no return value from this function
*/
function pause( iMilliseconds )
{
var sDialogScript = 'window.setTimeout( function () { window.close(); }, ' + iMilliseconds + ');';
window.showModalDialog('javascript:document.writeln ("<script>' + sDialogScript + '<' + '/script>")');
}
</script>

<%
sender = "asdf@asdf.com"

recipients = "abc@hotmail.com;def@hotmail.com;fff@hotmail.com"

subject = "testing"

strBody = "it's testing time"

endMail = 50 ' We send 50 mails each time
startMail = Request("page") * endMail

recipientsArr = Split( recipients, ";" )
recipientsCount = UBound(recipientsArr)

recipientsPage = Int(recipientsCount / endMail) ' Pages in total

For i = 0 To recipientsPage Step 1
startMailTmp = i * endMail
Response.Write "<a href='send.asp?page=" & i & "' id='link" & i & "'>" & startMailTmp & "</a>  "
If i Mod 10 = 9 Then
Response.Write "<br>"
End if
Next

Response.Write "<P>"

If Request("page") <> "" Then
If Int(startMail/endMail) = recipientsPage Then ' this is for dealing with last page problem.
endMail = recipientsCount Mod endMail +1
End If

endMail = (startMail + endMail) - 1

For i=startMail To endMail Step 1
Response.Write "#" & i & " " & recipientsArr(i) & ";"
Next
End if

%>

<%
If request("page") <> "" then
%>
<script type="text/javascript">
currentPage = <%= request("page") %>;
totalPage = <%= recipientsPage %>;
//alert( currentPage );
if( currentPage < totalPage ) {
document.write( "<p><span style='color:blue;'>We are going to page " + (currentPage+1) + "</span>");
pause(5000); // pause / sleep 5 seconds
document.getElementById("link" + (currentPage + 1)).click();
} else {
document.write( "<p><span style='color:red;font-size:100pt'>DONE!!!!!!!!!</span>" );
}
</script>
<%
End If

Function sendMail( sender, mailList, subject, strBody)
bodyformat = 0 ' 0:HTML, 1:text
mailformat = 0 ' 0:MIME, 1:text

set objmail = Server.CreateObject("CDONTS.Newmail")
objmail.From = sender
objmail.BodyFormat = bodyformat
objmail.MailFormat = mailformat
objmail.Subject = subject
'objmail.To = ""
objmail.Bcc = mailList
'objmail.Cc = ""
objmail.Body = strBody
objmail.Send()

set objmail=Nothing

Response.Write "done!"
End Function
%>

No comments: