Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How can I keep this from being sent twice?

Ninjas...

Below is the script that I'm using to facilitate the emailing of a newsletter. The problem is, my user is refreshing the screen and/or going to another page where he has the option to re-send the same content.

In theory, provided all the emails are sent, this wouldn't be an issue. But with 2000 plus emails going out, his box has a tendancy to time out which then produces an excellent environment to inadvertantly send out the same email twice.

What can I do to prevent this from happening. I thought about establishing a Session.Time_now variable and then qualifying what was going out by prefacing it with an "if" statement. That way if the page was refreshed, you would still have that Session variable to ensure that the same email wouldn't be going out to the person who's record had already been updated.

Before I start down this road, however, I wanted to let minds greater than my own weigh in on this. My question is, "Does what I described above sound like the best way to ensure that the same email wasn't going out twice, or is there a better way to do it?"

The code is below, I'm looking for any input and thank you in advance.

<%@ Language=VBScript %>
<%

set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open session("dbConn_ConnectionString")
set rsReminder = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM MTSSCustomers"
rsReminder.open sql,dbconn,3,3

Dateline = Replace(Request.Form("Dateline")," ","+")

Server.ScriptTimeout = 60000

Letter = Replace(Request.Form("Greeting"),vbCrLf,"<br>")

Dim aMailBody(7)

aMailBody(0) = "<font face=""arial narrow"" size=""3"">"
aMailBody(1) = Letter
aMailBody(2) = "<P>Click on the link below to access the ""Middle Tennessee Scuba and Swim QuickDip Newsletter!"" <P>If you have any questions, " _
& "contact MTSS at 615-771-0002 or emailing them at <A HREF=""mailto:rick@mtss.net"">rick@mtss.net</a>!<P>Here's the link:<P>"
aMailBody(3) = "<A HREF='" & server.htmlencode("http://www.brucegust.com/MTSS/QuickDip.asp?Dateline=" & Dateline) &"' target='blank'>http://www.brucegust.com/MTSS/QuickDip.asp?Dateline=" & Dateline & "</a>"
aMailBody(4) = "</font>"
emailbody = Join(aMailBody,"")


Set mailer = Server.CreateObject("ASPMAIL.ASPMailCtrl.1")


date_now = Now()
     
Do Until RSReminder.EOF

recipient = RSReminder("email")
sender = "MTSS@brucegust.com"
subject = "QuickDip - your MTSS Newsletter"
message = emailbody
mailserver = "mail.brucegust.com"

cTypeString = "text/html; charset=""iso-8859-1"""

result = Mailer.XHeader("Content-Type", cTypeString)

result = mailer.SendMail(mailserver, recipient, sender, subject, message)



sql2 = "update MTSSCustomers set LastSent = '" & date_now & "' "_
& "where email = '" & RSReminder("email") & "'"
DBConn.Execute sql2

RSReminder.MoveNext
Loop

set conn=nothing


response.redirect "NewsletterMailDone.htm"

%>
ASKER CERTIFIED SOLUTION
Avatar of chisholmd
chisholmd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hecatonchires
Hecatonchires

For an accidental refresh, checking the date not so great, because it also prevents you from sending more than one email a day.
Do it in two steps.
Step one - create the list of people to send email to.  Make this a feature: "Targetted email campaigns"
Get creative: people from certain areas, age groups, genders, etc.  maybe everyone with a certain widget in their purchase history
The selected people get inserted in another table with a 'processed' flag set to false

Step two - send the email
for each email sent, mark the selected person as processed.

at the end, either delete them, or keep it as a record of customer contact.

keep it as two seperate steps, that way if they refresh half way thru sending, they dont recreate the list of people to send it to again.
Your right, but I figured since its the Scuba Club newsletter I doubted he sent it more then once a day :)