We help IT Professionals succeed at work.

Need help converting a short script from ASPMail (I believe) to CDO

314 Views
Last Modified: 2010-05-18
I have a short script that I had been using to send email from an online form.

It used ASPMail (I believe).  But now that I am on a Windows 2008 server, I can't run ASPMail (which is what I believe it is using). So, I need someone's assistance (if I may ask) to make the changes in the script (shown below) from ASPMail (or what ever it is using) to using CDO instead.

Here's the script that I am currently using (that uses ASPMail).
==================================================

<%

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim FirstName
Dim LastName
Dim City
Dim State
Dim Email
Dim Reason
Dim Comments

' get posted data into variables
EmailFrom = Request.Form("Email")
EmailTo = "info@gordondesigns.com"
Subject = "Contact Form (gordondesigns.com): " & Request.Form("Reason")
FirstName = Trim(Request.Form("FirstName"))
LastName = Trim(Request.Form("LastName"))
City = Trim(Request.Form("City"))
State = Trim(Request.Form("State"))
Email = Trim(Request.Form("Email"))
Reason = Trim(Request.Form("Reason"))
Comments = Trim(Request.Form("Comments"))

' validation
Dim validationOK
validationOK=true
If (Trim(FirstName)="") Then validationOK=false
If (Trim(LastName)="") Then validationOK=false
If (Trim(City)="") Then validationOK=false
If (Trim(State)="") Then validationOK=false
If (Trim(Reason)="") Then validationOK=false
If (Trim(Comments)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("#")

' prepare email body text
Dim Body
Body = Body & "First Name: " & FirstName & VbCrLf
Body = Body & "Last Name: " & LastName & VbCrLf
Body = Body & "City: " & City & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "Email: " & Email & VbCrLf
Body = Body & "Reason for Contacting Us: " & Reason & VbCrLf

Body = Body & "Comments: " & Comments & VbCrLf

' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send

' redirect to success page
Response.Redirect("contact_thankyou.html")
%>

==================================================

So ... I need the above converted so it will use CDO (on a Windows 2008 server) instead.

Thanks,
Gary
Comment
Watch Question

Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
Here's an added note.

I installed CDONTS on the Windows 2008 server.  But ASPMail can't get installed.  So, if the script is CDONTS (it should be fine).  But if it's ASPMail, it won't run and will need to be modified to run using CDO.

Currently I am getting a script error that reads:

     Microsoft VBScript runtime error '800a0046'
     Permission denied
     /contact.asp, line 60

Again, I am on a Windows 2008 server.  I am not sure if permissions need to be modified somehow or not.    (The script shown above is the file  "contact.asp")

Please let me know what you think will get this script working.

Thanks,
Gary

Commented:
Try this, its working server 2003 code.

Sub SendEmail(mailTo, mailSubject, strHtmlBody)
 
Dim mailFrom, mailServer, mailUsername, mailPassword
 
 
mailServer = "smtp.aol.com"
mailFrom = "from@aol.com"
mailUsername = "user"
mailPassword = "pass"
 
 
requiredfname = Request.Form("requiredfname")
requiredlname = Request.Form("requiredlname")
company = Request.Form("company")
street = Request.Form("street")
street2 = Request.Form("street2")
city = Request.Form("city")
addystate = Request.Form("addystate")
zip = Request.Form("zip")
country = Request.Form("country")
requiredemail = Request.Form("requiredemail")
requiredpareacode = Request.Form("requiredpareacode")
requiredphone = Request.Form("requiredphone")
fareacode = Request.Form("fareacode")
fax = Request.Form("fax")
project = Request.Form("project")
 
mailFrom = "dldudrow@chs-incorp.com"
mailTo = "dldudrow@chs-incorp.com"
mailSubject = "Quote from CHS website"
strHtmlBody = "<HTML><HEAD></head><BODY>" & vbcrlf
strHtmlBody = strHtmlBody & "<p>" & requiredfname & " " & requiredlname
strHtmlBody = strHtmlBody & "<br>" & company
strHtmlBody = strHtmlBody & "<br>" & street
strHtmlBody = strHtmlBody & "<br>" & street2
strHtmlBody = strHtmlBody & "<br>" & city & ", " & addystate & " " & zip
strHtmlBody = strHtmlBody & "<br>" & country
strHtmlBody = strHtmlBody & "<br><br>"
strHtmlBody = strHtmlBody & "<br>" & requiredemail
strHtmlBody = strHtmlBody & "<br>" & requiredpareacode & "-" & requiredphone
strHtmlBody = strHtmlBody & "<br>" & fareacode & "-" & fax
strHtmlBody = strHtmlBody & "<br><br>"
strHtmlBody = strHtmlBody & "<br>" & project
strHtmlBody = strHtmlBody & "</p></body></html>"
 
 
Set MyMail = CreateObject("cdo.message")
MyMail.From = mailFrom
MyMail.To = mailTo
MyMail.Subject = mailSubject
MyMail.HTMLBody = strHtmlBody
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailUsername
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailPassword
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
MyMail.Configuration.Fields.Update
MyMail.Send
Set MyMail = nothing
 
End Sub
 
%>

Open in new window

Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
I'll try this shortly.

But do you know why I'm getting this error message and how to fix it on the Windows 2008 server?

Microsoft VBScript runtime error '800a0046'
Permission denied
/contact.asp, line 60

Gary

Commented:
Whats on line 60?

But it looks like you dont have permission to create the server object.
Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
Line 60 is:   mail.Send

How do I give permissions to this object on Windows 2008 Standard server?

I just moved things here and don't know how to do this.  Can you explain?

Thanks,
Gary

Commented:
I dont really know, but do you own the server? You could check if you have permission to run scripts (and have read/write/execute) in the IIS.
If you're behind a firewall then the permission denied probably is your firewall blocking the smtp connection to AOL's mail server.  In this scenario you should use an internal smtp mail relay as your smtp server.
Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
I am running on a VPS where I have root access and administrative rights on the server.

So, I need to know how to get rid of the message:

Microsoft VBScript runtime error '800a0046'
Permission denied
/contact.asp, line 60

which is occurring on the line:

mail.Send

I am trying to find out from someone .. what to do in order to correct the permission denied issue.
Any idea?  Again, I'm on a Windows 2008 server.  So, permissions are tighter than previously on Windows 2003, which I was running on.
Help??
Gary
 
Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
Let's get back to my initial request.

Can someone simply convert the following script .. so I can copy and paste it .. and have it use CDOSYS instead of CDONTS or ASPMail?

Here's the script again that I need to have converted.

Thanks.


============

<%

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim FirstName
Dim LastName
Dim City
Dim State
Dim Email
Dim Reason
Dim Comments

' get posted data into variables
EmailFrom = Request.Form("Email")
EmailTo = "info@gordondesigns.com"
Subject = "Contact Form (gordondesigns.com): " & Request.Form("Reason")
FirstName = Trim(Request.Form("FirstName"))
LastName = Trim(Request.Form("LastName"))
City = Trim(Request.Form("City"))
State = Trim(Request.Form("State"))
Email = Trim(Request.Form("Email"))
Reason = Trim(Request.Form("Reason"))
Comments = Trim(Request.Form("Comments"))

' validation
Dim validationOK
validationOK=true
If (Trim(FirstName)="") Then validationOK=false
If (Trim(LastName)="") Then validationOK=false
If (Trim(City)="") Then validationOK=false
If (Trim(State)="") Then validationOK=false
If (Trim(Reason)="") Then validationOK=false
If (Trim(Comments)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("#")

' prepare email body text
Dim Body
Body = Body & "First Name: " & FirstName & VbCrLf
Body = Body & "Last Name: " & LastName & VbCrLf
Body = Body & "City: " & City & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "Email: " & Email & VbCrLf
Body = Body & "Reason for Contacting Us: " & Reason & VbCrLf

Body = Body & "Comments: " & Comments & VbCrLf

' send email
Dim mail
Set mail = Server.CreateObject("CDONTS.NewMail")
mail.To = EmailTo
mail.From = EmailFrom
mail.Subject = Subject
mail.Body = Body
mail.Send

' redirect to success page
Response.Redirect("contact_thankyou.html")
%>


Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
Let's not worry about the error message I was getting.  I think I'll just try the script using CDO instead .. and then we'll go from there.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
That example is CDOSYS ^^

Quote:
How about CDONTs?
Microsoft has discontinued the use of CDONTs on Windows 2000, Windows XP


http://w3schools.com/asp/asp_send_email.asp
Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
psufan,

Thanks.  I'll test this shortly.  :-))Gary

Commented:
No problem, just ask if you have any other questions.
Gary GordonWebsite Developer, Designer, SEO and Online Marketing specialist.

Author

Commented:
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.