%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Session.Timeout=330
%>
<%
if request("button1") = "Send Mailout" then
' Get information from form and insert into database
DateSent = now()
CategoryID = request("lstCategory")
Subject = sqlsafe(request("txtSubject"), 255)
Message = sqlsafe(request("mailbody"), 998000)
MessageTextOnly = sqlsafe(request("mailbody"),998000)
IsHTML = false
query = "INSERT INTO IMailOut (IsHTML, MailOutDate, ICategoryID, Subject, Message, MessageTextOnly) VALUES (" & IsHTML & ",#" & DateSent & "#," & CategoryID & ",'" & Subject & "','" & Message & "','" & MessageTextOnly & "')"
DBConn.execute(query)
' 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
%>
ADMIN Quick Mailout |