% Option Explicit %>
<%
'Set the response buffer to false as we may need to puase while the e-mails are being sent
Response.Buffer = False
'Set the script timeout to 6 hours incase there are lots of e-mails to send
Server.ScriptTimeout = 21600
'Dimension variables
Dim rsMailList 'Database recordset variable
Dim strEmailBody 'Holds the body of the e-mail
Dim strAppendToEmail 'Holds the link to get removed from the mailing list
Dim strSubject 'Holds the subject of the e-mail
Dim blnEmailSent 'Set to true if the e-mail has been sent
Dim blnPreviewEmailSent 'Set to true if a preview e-mail has been sent
Dim lngNumberOfMembers 'Holds the number of mailing list members
Dim intEmailSentLoopCounter 'Lopp counter to count the number of e-mails sent
'Initialise variables
blnEmailSent = False
blnPreviewEmailSent = False
lngNumberOfMembers = 0
intEmailSentLoopCounter = 0
'If the session variable is False or does not exsist then redirect the user to the unauthorised user page
If Session("blnIsUserGood") = False or IsNull(Session("blnIsUserGood")) = True then
'Redirect to unathorised user page
Response.Redirect"unauthorised_user_page.htm"
End If
%>
Send E-mail to Mailing List Members
Return to the Mailing List menu Menu
<%
'If the e-mail is to be sent to all members then send it to all the mailing list members
If Request.Form("Submit") = "Send to All Members" Then
'Create the email body
'Read in the body of the e-mail
strEmailBody = Request.Form("body")
strSubject = Request.Form("subject")
'If the e-mail is in HTML format then change the format of the e-mail
If Request.Form("format") = "HTML" OR Request.Form("format") = "advHTML" Then
'Replace new lines with HTML new lines if requested
If Request.Form("format") = "HTML" AND Request.Form("lineBreak") = "true" Then strEmailBody = Replace(strEmailBody, vbCrLf, "
", 1, -1, 1)
'Let the e-mail client know were using HTML
strEmailBody = "" & strEmailBody
End If
'Strip out Norton Internet Security add blocking code that messes up emails
strEmailBody = Replace(strEmailBody, "", "", 1, -1, 1)
'Create recordset object
Set rsMailList = Server.CreateObject("ADODB.Recordset")
'Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblMailingList.* FROM tblMailingList;"
'Set the cursor type so we can do a record count
rsMailList.CursorType = 3
'Query the database
rsMailList.Open strSQL, adoCon
'Get the number of mailing list members
lngNumberOfMembers = rsMailList.RecordCount
'Create email object
Call createMailObject(strMailComponent)
'Display the HTML for sending the mail
'Display a message on the screen incase the user thinks nothing is happening and hits refresh sending the e-mail's twice
Response.Write("
The e-mail's are being sentDo not Hit Refresh or some members will receive the e-mail twice!
This may take some time depending on the speed of the mail server and how many e-mail's there are to send.
")
'Display the number of e-mails sent and how many left to send
Response.Write("
")
'Loop through the recordset and send the e-mail to everyone in the mailing list
Do While NOT rsMailList.EOF
'loop counter to count how many e-mails have been sent
intEmailSentLoopCounter = intEmailSentLoopCounter + 1
'Update the text box displaying the number of e-mails sent
Response.Write(vbCrLf & "")
'Write a remove from mailing list message to add to the end of the e-mail in HTML Format
strAppendToEmail = mailBody(Request.Form("format"), rsmailList("ID_Code"), blnLCode)
'Send the email
Call SendMail(rsmailList("Email"), strMailComponent, Request.Form("format"))
'Move to the next record in the recordset
rsMailList.MoveNext
Loop
'Write a message saying that all the e-mails have been sent
Response.Write(vbCrLf & "
Your email has now been sent to all the members of your mailing list. ")
'Drop email component
Call dropMailObject(strMailComponent)
'Set up the page response
blnEmailSent = True
'Reset server objects
rsMailList.Close
Set rsMailList = Nothing
'Else if this is a preview e-mail then send the preview to the web master
ElseIf Request.Form("Submit") = "Send Preview to Myself" Then
'Save the e-mail to a session variable so we can read it back
If Request.Form("format") = "advHTML" Then Session("strMailBody") = Request.Form("body")
'Read in the body of the e-mail
strEmailBody = Request.Form("body")
strSubject = Request.Form("subject")
'If the e-mail is in HTML format then change the format of the e-mail
If Request.Form("format") = "HTML" OR Request.Form("format") = "advHTML" Then
'Replace new lines with HTML new lines if requested
If Request.Form("format") = "HTML" AND Request.Form("lineBreak") = "true" Then strEmailBody = Replace(strEmailBody, vbCrLf, "