How can I keep this from being sent twice?

Posted on 2006-06-04
Medium Priority
Last Modified: 2008-02-26

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


set conn=nothing

response.redirect "NewsletterMailDone.htm"

Question by:brucegust
  • 2

Accepted Solution

chisholmd earned 2000 total points
ID: 16829992
why dont you check the last sent date in your first query

SELECT * FROM MTSSCustomers where LastSent <> '" & date_now & "' " 

You'll have to actualy parse the date down to just the date since your usin Now() which includes seconds etc.

Once you have the first query set to only select rows that have not yet been sent on this day you don't have to worry about the page being refreshed.  If your mailer chokes on a badly formated email address you just re run page confident that you won't email anyone twice.


Expert Comment

ID: 16830788
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.

Expert Comment

ID: 16831426
Your right, but I figured since its the Scuba Club newsletter I doubted he sent it more then once a day :)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question