Link to home
Start Free TrialLog in
Avatar of clayo
clayo

asked on

ASPX Contact form Email

I have an old script from a contact page that I have inherited.   I know nothing about aspx.  I have taken a few stabs at this but have failed everytime.  I get the following error

********************************************************************Error***********************************
Could not create an object of type 'CDONTS.NewMail'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Could not create an object of type 'CDONTS.NewMail'.

*******************************************End Error***************************************

My code is as follows:  

<%
' Website Contact Form Generator
' http://www.tele-pro.co.uk/scripts/contact_form/ 
' This script is free to use as long as you  
' retain the credit link  

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim EmailAddress
Dim State
Dim Company
Dim Message

' get posted data into variables
EmailFrom = "information@spiritcheer.com"
EmailTo = "information@spiritcheer.com"
Subject = "Web Contact"
Name = Trim(Request.Form("Name"))
EmailAddress = Trim(Request.Form("EmailAddress"))
State = Trim(Request.Form("State"))
Company = Trim(Request.Form("Company"))
Message = Trim(Request.Form("Message"))

' validation
Dim validationOK
validationOK=true
If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "EmailAddress: " & EmailAddress & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "Company: " & Company & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

' send email
Dim mail
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("index.html?" & EmailFrom)
%>


*******************************************************************End

I also know from research that this is the old way of sending mail.. Any help would be of assistance.

Avatar of Brad Howe
Brad Howe
Flag of Canada image

Hi,
Make sure that CDONTS.dll has been registered with the command:
 regsvr32 C:\WINDOWS\System32\CDONTS.dll

With that said, I would suggest using CDOSYS. CDONTS is deprecated.
http://www.w3schools.com/asp/asp_send_email.asp

Same structure, just a supported dll for windows2003.

Cheers,
Hades666
Avatar of clayo
clayo

ASKER

Ok I revised the code to:

<%
' Website Contact Form Generator
' http://www.tele-pro.co.uk/scripts/contact_form/ 
' This script is free to use as long as you  
' retain the credit link  

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim EmailAddress
Dim State
Dim Company
Dim Message

' get posted data into variables
EmailFrom = "information@spiritcheer.com"
EmailTo = "clayowensby@gmail.com"
Subject = "Web Contact"
Name = Trim(Request.Form("Name"))
EmailAddress = Trim(Request.Form("EmailAddress"))
State = Trim(Request.Form("State"))
Company = Trim(Request.Form("Company"))
Message = Trim(Request.Form("Message"))

' validation
Dim validationOK
validationOK=true
If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "EmailAddress: " & EmailAddress & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "Company: " & Company & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

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

<%
Set Mail=CreateObject("CDO.Message")
Mail.Subject=Subject
Mail.From=EmailFrom
Mail.To=EmailTo
Mail.TextBody=Body
Mail.Send
set myMail=nothing
%>

' redirect to success page
Response.Redirect("index.html?" & EmailFrom)
%>

But got the following error:


Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30037: Character is not valid.


 

Line 47: mail.Send
Line 48:
Line 49: <%
Line 50: Set Mail=CreateObject("CDO.Message")
Line 51: Mail.Subject=Subject
 
Avatar of clayo

ASKER

Ok so I blanked and did not take out one of the sections that you told me to.....  how does this look?

<%
' Website Contact Form Generator
' http://www.tele-pro.co.uk/scripts/contact_form/ 
' This script is free to use as long as you  
' retain the credit link  

' declare variables
Dim EmailFrom
Dim EmailTo
Dim Subject
Dim Name
Dim EmailAddress
Dim State
Dim Company
Dim Message

' get posted data into variables
EmailFrom = "information@spiritcheer.com"
EmailTo = "clayowensby@gmail.com"
Subject = "Web Contact"
Name = Trim(Request.Form("Name"))
EmailAddress = Trim(Request.Form("EmailAddress"))
State = Trim(Request.Form("State"))
Company = Trim(Request.Form("Company"))
Message = Trim(Request.Form("Message"))

' validation
Dim validationOK
validationOK=true
If (validationOK=false) Then Response.Redirect("error.htm?" & EmailFrom)

' prepare email body text
Dim Body
Body = Body & "Name: " & Name & VbCrLf
Body = Body & "EmailAddress: " & EmailAddress & VbCrLf
Body = Body & "State: " & State & VbCrLf
Body = Body & "Company: " & Company & VbCrLf
Body = Body & "Message: " & Message & VbCrLf

<%
Set Mail=CreateObject("CDO.Message")
Mail.Subject=Subject
Mail.From=EmailFrom
Mail.To=EmailTo
Mail.TextBody=Body
Mail.Send
set myMail=nothing
%>

' redirect to success page
Response.Redirect("index.html?" & EmailFrom)
%>

Avatar of clayo

ASKER

I got this error....

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30037: Character is not valid.

Source Error:

 

Line 38: Body = Body & "Message: " & Message & VbCrLf
Line 39:
Line 40: <%
Line 41: Set Mail=CreateObject("CDO.Message")
Line 42: Mail.Subject=Subject
 

Source File: C:\OS\public_html\New_SpiritCheer\site_flash\contact.aspx    Line: 40
Hi,

I just noticed this. you cannot use ASP code in a ASPX formated file.

ASPX is ASP.NET and typically coded in VB.NET or C#. The file extentions are .aspx
ASP on the other handle is the first version of ASP.NET. Essentially it HTML with server-side scripting enabled. The file extentions are .asp.

The code generated from your site creates 2 files.  
   1. An contact.htm file which acts as a webform that passes the parameters to the ASP page.
   2. An contact.asp File which contains the server objects to send the email.

As i mentioned earlier, I would start by reading the following (http://www.codeproject.com/KB/asp/cdoex.aspx). CDONTS is deprecated and CDOSYS is the supported format. Both links provide examples to help you set this up.

Cheers,
Hades666
Avatar of clayo

ASKER

This is a great link...  It still doesn't work...  Where do I set up the smtp properties in asp.  The server does not allow and open relay so I should need to give a username and password?
What language are you trying to write this in? .NET or regular ASP.

Thanks,
Hades666
Avatar of clayo

ASKER

asp
Hi Clayo,

Sorry you are having such a hardtime with this. In the forums it is always hard to gauge the users experience in programming and their environment configuration. With that said, please provide the following answers for me.

1. Do you have a smtp server installed and functioning on this webserver? If so, do you have an smart relay?To Test SMTP Server open command line and do the following:
 
    telnet yourserverip 25
    set local_echo            (! only if text not showing up)
    helo
    mail from:servername@yourdomain.com
    rcpt to: youremail@yourdomain.com
    data
    This is a test msg from the smtp server.
    .                              (! Finish and send the msg with a period like such)

This will test your smtp server configuration. If you don't receive and email of get a denied error, then you have  SMTP configuration issues and no smarthost smtp relay configured. We can correct this if that happens.

2. CDONTS CODE TO SENDEMAIL. Create an asp file called sendemail.asp with the following code between the ========. This code uses the CDONTS.DLL format even though it is deprecated. This does depend on CDONTS being registered if you are working off a windows 2003/2008 server.

CHANGE - yoursmtprelay.yourdomain.com
CHANGE - youremail@yourdomain.com

========
<%
  If Request.Form("btnSubmit") <> "" Then
    Dim UserName
    Dim UserMessage
    UserName = Request.Form("txtName")
    UserMessage = Request.Form("txtMessage")    
    Dim Message
    Message = Message & "User " & UserName & " left the following message: " & UserMessage

    Dim oMessage
    Set oMessage = Server.CreateObject("CDONTS.NewMail")

    With oMessage
      .To = "youremail@yourdomain.com"
      .From = "servername@yourdomain.com"
      .Subject = "User " & UserName & " left a message"
      .Body = Message
      .Send
    End with
    Set oMessage = Nothing
   
  End If
%>
<html>
<head></head>
<body>
  <form id="frmSendEmail" method="post" action="sendemail.asp">
    Your name: <input type="text" name="txtName" id="txtName" /><br />
    Your message: <input type="text" name="txtMessage" id="txtMessage" /><br />
    <input type="submit" name="btnSubmit" id="btnSubmit" value="Send Message" />
  </form>
</body>
</html>
========

IF your SMTP Server is configured correctly, you will receive an email.


3. CDOSYS CODE TO SENDEMAIL. Create an asp file called sendemail.asp with the following code between the ========. This code uses CDOSYS to send messages.

CHANGE - yoursmtprelay.yourdomain.com
CHANGE - youremail@yourdomain.com
CHANGE - serverip@yourdomain.com

========
<%
If Request.Form("btnSubmit") <> "" Then
  Dim UserName
  Dim UserMessage
  UserName = Request.Form("txtName")
  UserMessage = Request.Form("txtMessage")
  Dim Message
  Message = Message & "User " & UserName & " left the following message: " & UserMessage

  Const cdoSendUsingPort = 2

  Dim oConfiguration
  Dim oMessage
  Dim oFields
  Set oMessage = CreateObject("CDO.Message")
  Set oConfiguration = CreateObject("CDO.Configuration")

  Set oFields = oConfiguration.Fields
    With oFields
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "yoursmtprelay.yourdomain.com"
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
     .Update
    End With

  With oMessage
    Set .Configuration = oConfiguration
    .To = "youremail@yourdomain.com"
    .From = "serverip@yourdomain.com"
    .Subject = "User " & UserName & " left a message"
    .HTMLBody = Message
    .Send
  End With
End If

%>

<html>

<head></head>
<body>
  <form id="frmSendEmail" method="post" action="sendemail.asp">
    Your name: <input type="text" name="txtName" id="txtName" /><br />
    Your message: <input type="text" name="txtMessage" id="txtMessage" /><br />
    <input type="submit" name="btnSubmit" id="btnSubmit" value="Send Message" />
  </form>
</body>
</html>
========

4. Lastly, please provide the full code for you page(s). If your co-worker used http://www.tele-pro.co.uk/scripts/contact_form/. then you should have 2 files. One contact.htm and One contact.asp.


Let me know the outcome of the tests above.

Thank you,
Hades666
Avatar of clayo

ASKER

you are right..  This is the first time that I have ever touched asp...  I do not think that I have a smart relay on the box.  I continue to get errors when trying your smtp process above.  thank you for your help
hi Clayo,

No worries, diagnose and troubleshooting is the fun part. The challenge comes from how much detail to provide. Anyways, does your company have a smtprelay available for use? If so, try the following so see if you can relay of it. This test is the rawest form to ensure you can send email from this server.

  telnet yourcompany.smtpserver.com 25
    set local_echo            (! only if text not showing up)
    helo
    mail from:servername@yourdomain.com
    rcpt to: youremail@yourdomain.com
    data
    This is a test msg from the smtp server.
    .                              (! Finish and send the msg with a period like such)


Next is this a company? or a home site?

cheers,
Hades666
Avatar of clayo

ASKER

Ok so I have tested and can verify that I do have a smart relay on the server.  this is a company site
ASKER CERTIFIED SOLUTION
Avatar of Brad Howe
Brad Howe
Flag of Canada image

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
Avatar of clayo

ASKER

I am going to award you the points..  You have done more than your share on this question and I really appreciate that.  I have confirmed that there is a smart relay and have sent message multiple times with the cmd line scripts but I am still getting this error.

CDO.Message.1 error '80040213'

The transport failed to connect to the server.

/sendmail2.asp, line 32

I set the code up like this

  With oMessage
    Set .Configuration = oConfiguration
    .To = "clayowensby@gmail.com"
    .From = "cowensby@spiritcheer.com"
    .Subject = "User " & UserName & " left a message"
    .HTMLBody = Message
    .Send
  End With

I know that your example uses the server Ip and I tried that but I can't seem to get that to work with the cmd line example or with the code.  Any suggestions?
Hey Clayo,

No worries. Let's fix this completely.

Change --> Const cdoSendUsingPort = 1

Use the CdoSendUsing Enum to set this value. If the SMTP service is installed on the local computer, then the value defaults to cdoSendUsingPickup (1). Otherwise, if Microsoft Outlook/Express is installed, the value defaults to cdoSendUsingPort (2) and the settings from the default account are used. if it is 3 then it is directly with Exchange.

Finally, let's finish configuring your Local SMTP service this server to relay of the smarthost. Below are the settings/tabs to configure the smtp service to relay properly. It is restricted to only receive email from itself too :).


=================
General Tab
[x] Enable Logging

Access
      Access Control
            No Change leave Defaults
Secure communication
                  No Change leave Defaults
Connection Control
                  No Change leave Defaults
Relay restrictions
(*) Only the list below
<add>
(*) Single computer
Local.server.IP (Assigned IP)
127.0.0.1

      [  ] Allow all computers which successfully authenticate to relay, regardless of list above.

Messages
[  ] Limit Message size to (KB): 20000
[  ] Limit session size to (KB): 20000
[  ] Limited number of message per connection to:
[  ] Limit number of recipients per message to:

Send copy of Non-Delivery Report to:
            Leave empty

Delivery
Outbound
First retry interval (minutes): 15
Second retry interval (minutes): 30
Third retry interval (minutes): 45
Subsequent retry interval (minutes): 240
Delay notification: 12 Hours
Expiration timeout: 2 Days
Local
Delay notification: 12 Hours
Expiration timeout: 2 Days

Outbound Security button
                  No Change leave Defaults

Outbound Connections Button
                  No Change leave Defaults

Advanced Button
      Maximum Hops:      15
      Masquerade Domain:      <empty>
      FQDN:                  %Servername%
      Smart Host:            your.smtpserver.IP or DNS NAME

      [  ] Attempt Direct Delivery before sending to smart host
      [  ] Perform reverse DNS lookup on incoming messages

LDAP Routing
            No Change leave Defaults

Security
            No Change leave Defaults

Stop the Service
Start the Service for changes to take effect
================

After you change the cdosendport and setup the smtpservice, give it antoher shot.

Cheers,
Hades666
Avatar of clayo

ASKER

I must admit that I just found the issue.....  I didnt change the server name...  I tested it and it works...  you have been great and thank you so much!
excellent. Have a good one. - Hades666
Avatar of clayo

ASKER

you too
Avatar of clayo

ASKER

Just for knowledge how whould I authenticate to the smtp server??

  Set oFields = oConfiguration.Fields
    With oFields
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "mail.spiritcheer.com"
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
               .Item(cdoSendUsername) = "cowensby"  
        .Item(cdoSendPassword) = "GoDawgs1"
     .Update
    End With
Avatar of clayo

ASKER

this is great... thank you again.. the page works but I have not recieved the email message.  How could I award you more points?
Don't worry about it. Glad i could help.

Just wait and see it the email appears, sometimes going through a local smtp server then through a smarthost, the queue is a little slower then testing directly via command line and telnet.

Just hold tight.

Cheers, Hades666
Avatar of clayo

ASKER

here is the code

  Set oFields = oConfiguration.Fields
    With oFields
     .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")= "mail.xxxxxx.com"
     .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
       .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxxx"
.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxxx"
     .Update
    End With

Still no email