Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMTP Sending Mail Twice to Recipients

Status
Not open for further replies.

cjircita

MIS
Jan 9, 2002
14
0
0
US
I've written ASP code to send mail using the default SMTP server on a Windows 2000 Server box. My problem is 99.9 percent of the time the mail messages are being sent to each recipient twice. Less than 1 percent of the time a message will get sent only once.

My ASP code is simple (see below). The code gets generated from a subroutine called when the page posts back to itself. The subroutine simply updates a recordset from fields on the form and then runs the mail code below. Has anyone seen this before and perhaps could it be an SMTP problem? If not, could it be that the page is posting back to itself, perhaps running the mail code twice or something?

<%
set objmail = createobject(&quot;cdonts.newmail&quot;)
objmail.from = “me@mymailserver.com”
objmail.to = “them@theirmailserver.com”
objmail.subject = “this is the subject of your email”
num = “1”
ost = &quot;this is the body of the email. Click on this URL&quot;
url = &quot;objmail.body = ost & url & num
objmail.send
set objmail = nothing
%>
 
Can you post the whole asp page? The code from above should work fine!
 
Can't post this until tomorrow because my server is down. Please check back then. Thanks for willing to help.
Chris
 
It's pretty long: )
Just give me some time. I will see what I can do.
Durug
 
Oh, you're gonna love this!

I declared a session variable (called dcount) on the main page, then did a count on it in the zupdate routine where the mail code resides. I added 1 to dcount everytime it was supposed to go through the routine. Get this - on submit of the page, most of the time the routine runs twice (jumps two numbers). Every so often (like six, seven, eight or ten times) it only runs once.

This is weird.

Do you see anything at all?
 
It's very hard to figure out exactly what's going on on the page,The only thing that i could think of is that maybe the variable dlist is formed by 2 email addresses sometimes?

I give up. Sorry.
 
Hi cjircita,

I had a quick look at your code, and I'm afraid I have to suggest you learn how to split your code into modules. Look up the words cohesion and coupling in google to get an idea of what I am talking about.

A big part of programming is in planning, design, documentation, and a big reason for this, is when you need help you can get it :)

Its going to be very hard for a programmer to get in there in the depths of those 40 odd pages of code, and find your problem. Especially for free.

Is that the entire web site in that one page or just a single page? Its huge!!! :)

As a starting point, I'll tell you that you can keep javascript functions in external files and include them into your scripts. This will keep things much smaller already!! Also, lookup the #include directive, known as server side includes. You can use them to include common code in your scripts as if they were in the same file already! Finally, each page should have a single purpose. I think I spotted about 10 different database connections and queries. Surely this functionality can be split across multiple pages?

I hope this helps to steer you down the right path. If you need any more information just let me know :p Brett Birkett B.Comp
Systems Analyst
 
The answer:

I had a javascript subroutine that was doing the submit of the page after checking some fields - function checkdata(), document.chmodify.submit.

I had also copied a submit button tag from another page to change a former button that was an input type=&quot;button&quot;. The one I copied over was an input type=&quot;submit&quot;. I was executing two submits with the press of one submit button. Hence, two emails.

Fixed. Thanks to everyone for the tips and offers to help.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top