View Full Version : Using Cdonts to send several emails

Delfin Lazaro
07-23-2004, 12:52 AM
Im trying to use Cdonts to send email from a server hosted at godaddy.com.
I am able to send one email, but when I try to send a second email, it doesnt work. Basically, when someone fills out the form, they give me their email address. After they submit the form, I want to send two emails: one to myself and one back to the person saying his email was received (using the email he provided). When I only send one email, it works fine. But when I add the code to send a second email, it doesnt work.

The way Im trying to do it is by creating two mail objects and sending them separately. Is this a correct way to send two emails using the same asp file?

Here is my asp code. (The html form code is basic so I didnt include it - you can assume the email given is valid)
Any help would be great. thanks!



<% dim email

' Create first mail object
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")

' Set parameters
If IsObject(MyMail) Then
MyMail.From = "d_lazaro@hotmail.com"
MyMail.To = "d_lazaro@hotmail.com"
MyMail.Subject = "Testing mail script"
MyMail.BodyFormat = 0
MyMail.MailFormat = 1
MyMail.Importance = 2
MyMail.Body = "This is a test."
Set MyMail = Nothing
Response.write("message sent")
Response.write("message not sent")
End If

'The second mail object
Dim AutoReply
Set AutoReply = Server.CreateObject("CDONTS.NewMail")

'Set parameters
If IsObject(AutoReply) Then
AutoReply.From = "d_lazaro@hotmail.com"
AutoReply.To = email
AutoReply.Subject = "Email Confirmation"
AutoReply.BodyFormat = 0
AutoReply.MailFormat = 1
AutoReply.Importance = 2
AutoReply.Body = "Your Email has been received. "
Set AutoReply = Nothing
Response.write("second message sent")
Response.write("An error has occurred. Response not sent")
End If

Delfin Lazaro
07-23-2004, 01:27 AM
Just in case anyone wants to know, I had to use to recreate the same Mail object I created earlier, instead of declaring a new one.

07-23-2004, 03:08 PM
I have a very simple solution, don't use CDONTS, its not even supported by Microsoft anymore:

CDOSYS has replaced CDONTS, there is a great demo script on my site:

Try X-Send v1.1.2 for Windows Server 2000 and XP Professional.

07-28-2004, 06:55 AM
Perhaps put code like this after the first e-mail:
' Destroy object.
Set MyMail = Nothing

And perhaps put code like this after the second e-mail:
' Destroy object.
Set AutoReply = Nothing


Oops, sorry, I see that you already HAVE code like this after each e-mail.

But if you do decide to try CDO here are changes I made to convert CDONTS stuff to be CDO stuff instead:

o Change objCDONTS to be called objCDO (actually this is just a cosmetic change)

o This:
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")

Changed to this instead:
Set objCDO = Server.CreateObject("CDO.Message")

o This:
objCDONTS.Body = strEmailBody

Changed to this instead:
objCDO.TextBody = strEmailBody

o This removed:
' Importance.
' (0=Low, 1=Normal, 2=High)
objCDONTS.Importance = 1

And http://www.asp101.com/samples has some good e-mail examples such as the e-mail attachment example which uses the newer CDO (instead of the deprecated CDONTS which no longer ships with Windows).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum