Email using CDO

J

JayB

We sent out an email today to a list of subscribers from our database using
ASP and CDO. For some reason, many people received it twice, including
myself. I checked the database and there were do duplicate records and I
know for sure that I have no other email address forwarding email. I checked
my code and all seems ok. Perhaps someone can take a look at it and see if I
screwed up somewhere? It was sent to over 9,000 email addresses. When I sent
a test email from the database to 16 internall email addresses, everyone got
it just fine and only received one copy, as planned.

<%
rs.Open SQL, ConStr
rs.movefirst
do until rs.eof = true
strCount = strCount + 1
for i=1 to number
Set myMail = CreateObject("CDO.Message")
myMail.From = "(e-mail address removed)"
myMail.To = rs("EmailAddress")
myMail.Subject = "PACER eNewsletter"
myMail.HTMLBody = content
myMail.Send
Set myMail = Nothing
next
rs.movenext
loop
rs.close
%>

Before I sent the email, I tested this code by replacing everything in the
for loop with a response.write strCount & " " & rs("EmailAddress") just to
make sure it doesn't write any of the email addresses more than once.

Could this be an issue with the SMTP service on my server?

Thanks,
 
R

Ray Costanzo [MVP]

Isn't it possible that someone ran the script twice or two people ran it
once?

Ray at work
 
A

Aaron [SQL Server MVP]

Well, where is the variable "number" defined and populated? Why do you have
two loops (do until rs.eof = true AND for i = 1 to number)? Are you meaning
to send more than copy of the newsletter to each recipient? This code looks
suspiciously like it could do exactly that.
 
J

JayB

No. I'm the only one who has access to it. I wish that scenerio were
possible though ;-)

--
JayB

Ray Costanzo said:
Isn't it possible that someone ran the script twice or two people ran it
once?

Ray at work
 
J

JayB

Sorry, I forgot that part.
After I dim the variable i, I set it to 1. I put in the for loop this way to
ensure that it only sent out once per record (so I thought). I did send it
to 16 test email accounts from a test table using the same code and it
worked great. I also took the CDO code out and replaced it with a
response.write in an ordered html list to compare and each email address
appeared only once.

--
JayB


Aaron said:
Well, where is the variable "number" defined and populated? Why do you
have
two loops (do until rs.eof = true AND for i = 1 to number)? Are you
meaning
to send more than copy of the newsletter to each recipient? This code
looks
suspiciously like it could do exactly that.
 
J

Jeff Dillon

Yes, remove the unneccessary loop

Jeff

JayB said:
Sorry, I forgot that part.
After I dim the variable i, I set it to 1. I put in the for loop this way to
ensure that it only sent out once per record (so I thought). I did send it
to 16 test email accounts from a test table using the same code and it
worked great. I also took the CDO code out and replaced it with a
response.write in an ordered html list to compare and each email address
appeared only once.
 
J

JayB

Jeff,

I'm not sure how this solves the problem. When I tested with 16 email
addresses, it worked fine. When I tested by writing each of the 9800 email
addresses to the browser instead of sending the email to each, it worked
fine. If the extra loop was the problem, these tests would have produced
duplicated results.

Is there a chance that it could be an issue with the server? There's 1.5GB
of RAM in it and each email message was only 11KB. Perhaps there's an issue
with the SMTP service?
 
J

Jeff Dillon

Perhaps Server.CreateObject? And create it only once, and reuse it? And no
need for movefirst for a default forward only cursor.

Just suggesting ideas. Yes, it could be an SMTP issue..perhaps it times out
on a message, and tries again. Not sure. First, create solid code.

Jeff
 
J

JayB

I cleaned up the code big time. Also I found the connection timeout setting
on the SMTP server set to 10 minutes. After looking at the log files it
looks as though most people who received their email twice received the
second one around 10 minutes after their first one. I extended this time and
will see how it works.

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top