Link to home
Start Free TrialLog in
Avatar of VirusMinus
VirusMinusFlag for Australia

asked on

Email scripts sending email twice

Hi Guys,

I'm running some websites on a new windows 2003 server.

I'm using CDOSYS and Jmail to send out emails via web forms.

Problem is both scripts send out the same email twice abotu 80% of the time.

I'm calling the email script only once, set up exactly one recipient, zero CCs and zero BCCs

The emails arrive with the same time stamp.

About 80% of the time the email is sent twice with identical contents but different mail IDs. The rest of the time it's sending once.

What could be the problem and how can I locate and fix it?

Cheers,
VM
Avatar of Irwin Santos
Irwin Santos
Flag of United States of America image

stuck in queue?

is it possible to post your code please?
try to send smiple mail just for testing purpose.

Set objMail = Server.CreateObject("CDONTS.NewMail")
                              objMail.BodyFormat = 0
                              objMail.MailFormat = 0
                              objMail.From =  "You@your.com
                              objMail.To = "test@test.com"
                              objMail.Subject = "testing"
                              objMail.Body = "Hi this is just a test"
                              objMail.Send
                              Set objMail = Nothing
i missed "


Set objMail = Server.CreateObject("CDONTS.NewMail")
                         objMail.BodyFormat = 0
                         objMail.MailFormat = 0
                         objMail.From =  "You@your.com"
                         objMail.To = "test@test.com"
                         objMail.Subject = "testing"
                         objMail.Body = "Hi this is just a test"
                         objMail.Send
                         Set objMail = Nothing
Avatar of JohnModig
JohnModig

Hi VM.
There are two methods for sending an email with CDOSYS:

1. Using an SMTP server
2. Using a pickup folder

Which one are you using? (Info about differences: http://www.snook.ca/archives/active_server_pages/cdosys_the_diff/) Also, make sure that your code (ASP?) is not reloading the code that sends email in any way (using response.redirect or similar). I would be happy to try to help out, but I need to see some code first. Please post your code and Ill see what I can do.

Regards,
John
Avatar of VirusMinus

ASKER

My CDOSYS function:
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

'----------------------------------------------------------------------------------------------------------------
Function SendEmailCDOSYS(strInputTo, strInputFrom, strInputSubject, strInputMsg, iOptHTMLOn, iInputImportance, BCCEmailAddress)

 if Instr(Request.ServerVariables("SERVER_NAME"),"192.") OR Instr(Request.ServerVariables("SERVER_NAME"),"127.") then

      Response.write "<!-- ******** EMAIL SENT ******** --><!--" & vbcrlf & _
                                          "<br><strong>To: </strong> " & vbcrlf & strInputTo & _
                                          "<br><strong>From: </strong> " & vbcrlf & strInputFrom & _
                                          "<br><strong>Subject: </strong> " & vbcrlf & strInputSubject & _
                                          "<br><strong>Message: </strong> " & vbcrlf & strInputMsg & _
                                          "<br><strong>HTML On: </strong> " & vbcrlf & iOptHTMLOn & _
                                          "<br><strong>Importance: </strong> " & vbcrlf & iInputImportance & _
                                          "<br><strong>BCC: </strong> " & vbcrlf & BCCEmailAddress & vbcrlf & _
                                          "--><!-- ******** EMAIL SENT ******** -->" '& "<script>alert('Mail Sent! Text in Source')</script>"
else

      Dim objMessage      
      
      Set objMessage = Server.CreateObject("CDO.Message")
      objMessage.Subject = strInputSubject
      objMessage.Sender = strInputFrom
      objMessage.From = "Melbourne VIP <" & strInputFrom & ">"
      objMessage.To = strInputTo
      if BCCEmailAddress <> "" then
            objMessage.Bcc = BCCEmailAddress
      end if
      objMessage.HTMLBody = "<html><head><title>Email Message</title></head><body><p><font face=""Arial"" size=""2"">" & strInputMsg & _
                                                 "</font></p></body></html>"
      
      '==This section provides the configuration information for the remote SMTP server.
      
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      
      'Name or IP of Remote SMTP Server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
      
      'Type of authentication, NONE, Basic (Base64 encoded), NTLM
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
      
      'Your UserID on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "info@melbournevip.com.au"
      
      'Your password on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "carlos"
      
      'Server port (typically 25)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      
      'Use SSL for the connection (False or True)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
      
      'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      
      objMessage.Configuration.Fields.Update
      objMessage.Send
      
      On Error Resume Next
      If Err.number <> 0 then     'if there is an error
            response.write ("Error with email address:"  & strInputTo & "<br />")
      End If
      
      Set objMessage = Nothing

End if

End Function
'----------------------------------------------------------------------------------------------------------------
This function is inside an include and i call the function when the form is submitted
Similarly my Jmail function:

Function SendEmail(strInputTo, strInputFrom, strInputSubject, strInputMsg, iOptHTMLOn, iInputImportance, BCCEmailAddress)
 
            Dim JMail
            Set JMail = Server.CreateObject("JMail.SMTPMail")
 
            JMail.ServerAddress = "mail.mydomain.net.au"
            JMail.AddHeader "X-Originating-IP", Request.ServerVariables("REMOTE_ADDR")
            JMail.Priority = iInputImportance
            JMail.Sender = strInputFrom
            JMail.AddRecipient strInputTo
           
            JMail.Message.MailServerUserName="myserver.mydomain.com"
            JMail.Message.MailServerPassWord="password"
           
                        if BCCEmailAddress <> "" then
                                    JMail.AddRecipient(BCCEmailAddress)
                        end if
            JMail.Subject = strInputSubject
            JMail.ContentType = "text/html"
            JMail.Body = "<html><head><title>Email Message</title></head><body><p><font face=""Arial"" size=""2"">" & strInputMsg & _
                                                                                     "</font></p></body></html>"
            JMail.Execute
             
            'release resources
            JMail.Close      
            set JMail = nothing
 
End Function
Ok, remember that I said there were two ways of sending methods using CDOSYS? This line in your code:

 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

Means you are using the SMTP method to send your email. Because of that, you need to specify an address to the SMTP server (outgoing email server). In your code, this line does just that:

 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"

...but is this really the right? Is the address to the SMTP server really "localhost" (the computer you are running the code from)? In your JMail code the address to the SMTP server is:
 
 mail.mydomain.net.au

Of course, that is not the real address, but just an example. However, I am sure that this is more or less what the SMTP server address should look like. Check with your ISP and find out the real address to the SMTP server and substitute the "localhost" for that in your code. Actually, I just did a quick ns lookup and it looks to me like your SMTP server name is: mail.melbournevip.com.au - so try and change this line:

 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"

...to this line:

 ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.melbournevip.com.au"
 
Let me know how it went.

 
I put in localhost as an example as well. I know the smtp server name. The script is working of the smtp server as mentioned, but still sending double emails.
Ok, good. Then the email scipt looks fine to me. Maybe it has something to do with the way you implement it? You are using it as an include, right? Is the include line on the same page as the form? Or is it setup in such a way that the user might be using the back-button and therefore calling the script twice? Maybe I need to see your ASP code as well.

Just to make sure that there is nothing wrong with the script - make an ASP page with JUST the script and a simple body message and your self as the recipient - nothing else, no post or form. Then call it from your webbrowser. If you only recieve one email - that means your problem is somewhere in the ASP code that calls the function.
ok.. i did some testing and have some strange results to report.

i made an seperate asp page called cdosys.asp

this is the code for that page:

<%

Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

'---------------------------------------------------------------------------------------------------

-------------
Function SendEmailCDOSYS(strInputTo, strInputFrom, strInputSubject, strInputMsg, iOptHTMLOn,

iInputImportance, BCCEmailAddress)

      Dim objMessage      
      
      Set objMessage = Server.CreateObject("CDO.Message")
      objMessage.Subject = strInputSubject
      objMessage.Sender = strInputFrom
      objMessage.From = "Art of Australia <" & strInputFrom & ">"
      objMessage.To = strInputTo
      if BCCEmailAddress <> "" then
            objMessage.Bcc = BCCEmailAddress
      end if
      objMessage.HTMLBody = "<html><head><title>Email Message</title></head><body><p><font

face=""Arial"" size=""2"">" & strInputMsg & _
                                                 "</font></p></body></html>"
      
      '==This section provides the configuration information for the remote SMTP server.
      
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      
      'Name or IP of Remote SMTP Server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mydomain.net.au"
      
      'Type of authentication, NONE, Basic (Base64 encoded), NTLM
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
      
      'Your UserID on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
      
      'Your password on the SMTP server
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
      
      'Server port (typically 25)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
      
      'Use SSL for the connection (False or True)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
      
      'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to

the SMTP server)
      objMessage.Configuration.Fields.Item _
      ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      
      objMessage.Configuration.Fields.Update
      objMessage.Send
      
      On Error Resume Next
      If Err.number <> 0 then     'if there is an error
            response.write ("Error with email address:"  & strInputTo & "<br />")
      End If
      
      Set objMessage = Nothing



End Function
'---------------------------------------------------------------------------------------------------

-------------
Call SendEmailCDOSYS("myemail@mydomain.com.au", "from@mydomain.net.au", "CDO SYS Message", "hi, this

is a test cdo sys message", 1, 1, "")
%>

Now i tested it by sending it to three different email addresses, my work email, my home email and my gmail

at work out of three tests, twice i got double emails
at my home out of three tests, all three times i got double emails
at gmail out of ten tests, only once i got double emails

I'm more perplexed than before now. Gmail seems to receive one, the rest two.
That is weird. As far as I can see, there is nothing in that code that could make it execute twice. So, we need to rule out that nothing is wrong with the SMTP server. Is there any other email component installed on the webserver? Jmail? What if you try to send an email using that? Does that get delivered twice as well?
Could be this...
http://support.microsoft.com/kb/254286/EN-US/
Also, the "on error resume next" won't work the way it's coded.
This problem remains unresolved. Please Delete and PAQ if info is useful.
please visit the link i provided above to see ways that you can maintain your own questions.  you have not responded to some of the experts and the moderators may not give you a refund until you have done so.
@JohnModig: Yes, jmail also shows the same behaviour

@joeposter649: i removed on error resume next. no go. I'm not so sure about that article.

I've left this in the hands of the Hosting service provider. I've got bigger fish to fry at the moment. If I ever find out what was causing it i'll be sure to post back.
ASKER CERTIFIED SOLUTION
Avatar of JohnModig
JohnModig

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