%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Session.Timeout=330
%>
<%
if request("button1") = "Send Mailout" then
' Get information from form and insert into database
if request("EmailFormat") = "html" then
IsHTML = true
MessageTextOnly = sqlsafe(request("mailbodytextonly"),998000)
else
IsHTML = false
MessageTextOnly = sqlsafe(request("mailbody"), 998000)
end if
DateSent = now()
CategoryID = request("lstCategory")
Subject = sqlsafe(request("txtSubject"), 255)
Message = sqlsafe(request("mailbody"), 998000)
MessageTextOnly = sqlsafe(request("mailbodytextonly"),998000)
query = "INSERT INTO IMailOut (IsHTML, MailOutDate, ICategoryID, Subject, Message, MessageTextOnly) VALUES (" & IsHTML & ",#" & DateSent & "#," & CategoryID & ",'" & Subject & "','" & Message & "','" & MessageTextOnly & "')"
DBConn.execute(query)
' If the user has selected to save the mail as a template then save it in the mailouttemplate table
if request("chksavetemplate") = "yes" then
query = "INSERT INTO IMailOutTemplate (IsHTML, MailOutDate, ICategoryID, Subject, Message) VALUES (" & IsHTML & ",#" & DateSent & "#," & CategoryID & ",'" & Subject & "','" & Message & "')"
DBConn.execute(query)
end if
' Get the IMailOutID of the recently inserted record
query = "SELECT * FROM IMailOut WHERE Subject = '" & Subject & "' AND MailOutDate = #" & DateSent & "#"
set rsID = DBConn.execute(query)
if not rsID.EOF then
IMailOutID = rsID("IMailOutID")
end if
rsID.Close
set rsID = nothing
' Get all UserIDs from the IMailingList table that match the category
' Insert each of these into the IMailOutSent Table along with the mailoutid, set status to not sent
query = "Select * from IMailingList WHERE ICategoryID = " & CategoryID & " AND isActive = true"
set rsUser = DBConn.execute(query)
do until rsUser.EOF
query = "INSERT INTO IMailSent(IMailOutID, IMailingListID, MailSent) VALUES (" & IMailOutID & "," & rsUser("IMailingListID") & ", false)"
DBConn.execute(query)
rsUser.movenext
loop
rsUser.Close
set rsUser = nothing
' Get details of the particular mailout
query = "SELECT * FROM IMailOut WHERE IMailOutID = " & IMailOutID
set rsMailOut = DBConn.execute(query)
if not rsMailOut.EOF then
IsHTML = rsMailOut("IsHTML")
DateSent = rsMailOut("MailOutDate")
CategoryID = rsMailOut("ICategoryID")
Subject = rsMailOut("Subject")
Message = rsMailOut("Message")
MessageTextOnly = rsMailOut("MessageTextOnly")
end if
rsMailOut.Close
set rsMailOut = nothing
' Check that there is actually a mail subject, message etc to send before attempting to
if Subject <> "" then
response.write("Sending Mail .")
'Attempt to send the mail to each of the recipients in the list
query = "SELECT * FROM IMailSent WHERE IMailOutID = " & IMailOutID & " AND MailSent = false"
set rsSend = DBConn.execute(query)
do until rsSend.EOF
' Get the user id of the user to send mail to
IUserID = rsSend("IMailingListID")
' Get the email address and name of the recipient to send the mail to
query = "SELECT * FROM IMailingList WHERE IMailingListID = " & IUserID
set rsUser = DBConn.execute(query)
if not rsUser.EOF then
emailrecipient = rsUser("Email")
emailpassword = rsUser("ActivationCode")
'recipientname = rsUser("RecipientName")
IsHTML = rsUser("HTMLEmail")
' Put the unsubscribe info into the mailout message
MessageToSend = ""
sTrailerText = "to unsubscribe, use this link http://" & Request.ServerVariables("SERVER_NAME") & LocationPhyPath & "unsubscribe.asp?EmailAddress=" & emailrecipient & "&ActivationCode=" & emailpassword
sTrailerHTML = "to unsubscribe, click here"
If IsHTML = false Then
MessageToSend = sTrailerText & vbCrLf & MessageTextOnly & vbCrLf & sTrailerText
Else
MessageToSend = sTrailerHTML & "
" & Message & "
" & sTrailerHTML
End If
' If they are using jmail then use this function
if MAIL_COMPONENT = "Jmail" then
Set JMail = Server.CreateObject("jmail.smtpmail")
JMail.ServerAddress = MAIL_SERVER
if IsHTML then
JMail.ContentType = "text/html"
else
JMail.ContentType = "text/plain"
end if
JMail.AddRecipient rsUser("Email")
JMail.Sender = SENDER_EMAIL
JMail.SenderName = SENDER_EMAIL_NAME
JMail.Subject = Subject
JMail.Body = MessageToSend
JMail.Logging = True
JMail.Execute
set JMail = Nothing
else
' otherwise do this
' Attempt to send email to recipient
SendEmail MAIL_COMPONENT, MAIL_SERVER, emailrecipient, "", "", SENDER_EMAIL, SENDER_EMAIL_NAME, SENDER_EMAIL, SENDER_EMAIL_NAME, Subject, MessageToSend, "", IsHTML
end if
' If successful mark the email as sent
currentdate = now()
query = "UPDATE IMailSent SET MailSent = true, DateSent = #" & currentdate & "# WHERE ID = " & rsSend("ID")
DBConn.execute(query)
response.write(".")
end if
rsUser.close
set rsUser = nothing
rsSend.movenext
loop
rsSend.Close
set rsSend = nothing
end if
end if
' Get information about the selected template if the user chose one
ICategoryID = 1
if request("IMailOutTemplateID") <> "" then
query = "SELECT * from IMailOutTemplate WHERE IMailOutTemplateID = " & request("IMailOutTemplateID")
set rsDropDown = DBConn.execute(query)
if not rsDropDown.EOF then
IMailOutTemplateID = rsDropDown("IMailOutTemplateID")
IsHTML = rsDropDown("IsHTML")
MailOutDate = rsDropDown("MailOutDate")
ICategoryID = rsDropDown("ICategoryID")
Subject = rsDropDown("Subject")
Message = rsDropDown("Message")
end if
rsDropDown.close
set rsDropDown = nothing
end if
' Check if user has selected something from the newsletter section to email
' This will oopen a connection to the website database and retrieve the content for the chosen section
if request("pg") <> "" then
pg = request("pg")
Message = ""
IsHTML = true
Set DBConnWeb = Conn.execute(query)
querya = "SELECT Menu.id, Menu_Content.Menuid, Menu.MenuName, Menu_Content.Contentid "_
&" FROM Menu INNER JOIN Menu_Content ON Menu.id = Menu_Content.Menuid "_
&" WHERE Menu.id = " & pg & " And Menu_Content.Menuid = " & pg & " "
Set rsBlankCheck = DBConnWeb.execute(querya)
if rsBlankCheck.EOF then
'code for when there is NO content
' start blank check display -------------------------------------------
queryb = "SELECT * From Content "_
& "WHERE ContentName = '" & "front page" & "' "
Set rsBlankPrint = DBConnWeb.execute(queryb)
do until rsBlankPrint.EOF
Message = Message & rsBlankPrint("ContentBody")
rsBlankPrint.movenext
loop
rsBlankPrint.close
set rsBlankPrint = nothing
'finish blank check display -------------------------------------------
else
'code for when there is YES content
' start with content check display -------------------------------------------
query = "SELECT Content.Contentid, Content.ContentName, " _
& "Content.ContentBody, Menu_Content.ContentOrder " _
& "FROM Content INNER JOIN Menu_Content ON Content.Contentid = Menu_Content.Contentid " _
& "WHERE Menu_Content.Menuid=" & pg
Set rsContent = DBConnWeb.execute(query)
do until rsContent.EOF
Message = Message & rsContent("ContentBody")
rsContent.movenext
loop
rsContent.close
set rsContent = nothing
end if
rsBlankCheck.close
set rsBlankCheck = nothing
DBConnWeb.close
set DBConnWeb = nothing
end if
%>
![]() |