Solved

trying to send email by submitting page using ASP.net

Posted on 2011-09-06
29
491 Views
Last Modified: 2012-05-12
I have a web application that makes entry through an HTML page. One of those HTML pages I am putting in a register area for potential clients. I want, when the submit button is clicked, to email me the information without asking the client to verify there email settings etc. I just want it to be transparent to the client. I found some code that suggests attaching an asp page to the action event of the form tag as below...

form portion of the html page
<form method="post" action="IndexToMail.asp">
    <table style="width: 420px;">
          <tr>
                 <td style="font-size: small; width: 130px;">
                       Company Name:
                 </td>
                 <td style="font-size: small;">
                        <input id="CompanyName" type="text" style="width: 280px" />
                 </td>
         </tr>
         <tr>
                <td style="font-size: small;">
                         Address:
               </td>
               <td style="font-size: small;">
                         <input id="Address" type="text" style="width: 280px" />
               </td>
          </tr>
          <tr>
                <td style="font-size: small;">
                          City, St, Zip:
                 </td>
                 <td style="font-size: small;">
                          <input id="City" type="text" style="width: 120px" />
                              <select id="State" style="width: 55px">
                                    <option value="AK">AK</option>
                                      ...states
                               </select>
                           <input id="Zip" type="text" style="width: 93px" />
                  </td>
           </tr>
           <tr>
                  <td style="font-size: small;">
                             Phone:
                 </td>
                <td style="font-size: small;">
                            <input id="Phone" type="text" style="width: 280px" />
                 </td>
            </tr>
            <tr>
                 <td style="font-size: small;">
                             Contact:
                  </td>
                  <td style="font-size: small;">
                          <input id="Contact" type="text" style="width: 280px" />
                   </td>
             </tr>
             <tr>
                 <td style="font-size: small;">
                            &nbsp
                  </td>
                  <td align="right" style="font-size: small;">
                            <input id="cmdSubmit" type="submit" value="Submit" />
                  </td>
             </tr>
     </table>
 </form>

Open in new window


asp page
<%@  language="VBscript"  %>
<% Option Explicit %>
<html>
<head>
    <title>Message Sent</title>
</head>
<body>
    <%

        Dim name, address, city, state, zip, phone, contact
        name=request.form("CustomerName")
        address=request.form("Address")
        city=request.form("City")
        state=request.form("State")
        zip=request.form("Zip")
        phone=request.form("Phone")
        contact=request.form("Contact")

        'create the mail object and send the details
        Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
        NewMailObj.From = ... email address
        NewMailObj.To =  ... email address
        NewMailObj.Subject = "Customer signed up"
        NewMailObj.Body = "Customer Name: " & name & _
        "<br>Address: " & address & _
        "<br>City: " & city & _
        "<br>State: " & state & _
        "<br>Zip: " & zip & _
        "<br>Phone: " & phone & _
        "<br>Contact: " & contact 

        'you need to add the following lines FOR the mail to be sent in HTML format
        NewMailObj.BodyFormat = 0
        NewMailObj.MailFormat = 0
        NewMailObj.Send
        'Close the email object and free up resources
        Set NewMailObj = nothing
        Response.write "The email was sent."
    %>
</body>
</html>

Open in new window


I get this error from dev environment
     "The HTTP verb POST used to access path '/IndexToMail.asp' is not allowed."

and I get a 500 error in production


not sure exactly how to make this work the way I want....  I tried using an .aspx page but whenever I tried to extract the data using Request.Form("CustomerName") it always came back as nothing so I tried using just an asp page but still no luck.

Thanks.
0
Comment
Question by:md0333
  • 15
  • 12
  • 2
29 Comments
 
LVL 15

Expert Comment

by:pateljitu
ID: 36491402
The sample code you are using is for Classic ASP and DOTNET version, please use this article as reference for sending email using ASP.NET

http://www.4guysfromrolla.com/articles/072606-1.aspx
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36491405
So, which part of your code is causing this problem?

I can't seem to find it.
0
 

Author Comment

by:md0333
ID: 36491467
pateljitu - OK... I see what they are doing there but my page is an HTML page.... not an .aspx page so I don't have code behind to access a sub. Can I do the same thing with javascript? Or other options?
0
 
LVL 15

Expert Comment

by:pateljitu
ID: 36491769
1. Can you try renaming the file extension from .html to .asp for test purpose (this is the page where user fills in form information) and try send email functionality by clicking Submit button.  

2. What version of IIS are you using?
0
 

Author Comment

by:md0333
ID: 36492264
when I rename the page with extension  .asp then I get this error.

"The type of page you have requested is not served because it has been explicitly forbidden.  The extension '.asp' may be incorrect. "

I am using IIS7.5
0
 

Author Comment

by:md0333
ID: 36492370
OK... I switched my dev environment to run off of IIS express and the page came up now...  but when I click to send the email I get the same HTTP 500 Internal server error.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492527
post ALL your code here.
0
 

Author Comment

by:md0333
ID: 36492531
I did... in the first post...
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492687
Well, first of all, let's fix your browser.

Fire up internet explorer

Click on Internet Options

Click on Advanced tab

Scroll down till you see a checkbox that says, "show http Friendly error messages"

Uncheck it

Apply

Ok
close then run your code again.

What is the error you get now?
0
 

Author Comment

by:md0333
ID: 36492694
new error:

Server object error 'ASP 0177 : 800401f3'

Server.CreateObject Failed

/IndexToMail.asp, line 23

800401f3
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492712
which of the 2 files is IndexToMail.asp?
0
 

Author Comment

by:md0333
ID: 36492719
the asp page... the first page is .htm.

the asp page has the
     Set NewMailObj=Server.CreateObject("CDONTS.NewMail")

0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492888
Ok, here are a few things we need  to do:

First, do you have smtp installed?

If yes, go to step 3.

If no, then

step2: follow this link to install it:

http://forums.iis.net/t/1157046.aspx

Step3. We assume smtp is installed.

Then download the attachment. It is called cdonts.zip

Unzip it. Don't worry I tested it and used it.

After unzipping it, copy the only file you see called cdonts.dll into your system32 directory.

Thats C:\Windows\System32 and dump it there.

Step4: Register it by opening up command prompt and copy and paste the following:

regsvr32 c:\windows\system32\cdonts.dll
Then hit the enter key. If you follow my instructions correctly, you should get registration succeeded.

Step5: Use the following code.

I made some slight changes. It is good practice to use Name instead of ID like:

<input name="contact" type="text" value="">

First it is faster. Second, it will register on next page and your code should see it.

It would not have seen it with id="contact"

    <%

        Dim name, address, city, state, zip, phone, contact
        name=request.form("CustomerName")
        address=request.form("Address")
        city=request.form("City")
        state=request.form("State")
        zip=request.form("Zip")
        phone=request.form("Phone")
        contact=request.form("Contact")

        'response.write contact
        'response.end


        Dim NewMailObj

        'create the mail object and send the details
        Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
        NewMailObj.From =request.form("Contact")
        NewMailObj.To = "youremail.com"
        NewMailObj.Subject = "Customer signed up"
        NewMailObj.Body = "Customer Name: " & name & _
        "<br>Address: " & address & _
        "<br>City: " & city & _
        "<br>State: " & state & _
        "<br>Zip: " & zip & _
        "<br>Phone: " & phone & _
        "<br>Contact: " & contact

        'you need to add the following lines FOR the mail to be sent in HTML format
        NewMailObj.BodyFormat = 0
        NewMailObj.MailFormat = 0
        NewMailObj.Send
        'Close the email object and free up resources
        Set NewMailObj = nothing
        Response.write "The email was sent."
    %>
  <form method="post" id=form1 name=form1>
    <table style="width: 420px;">
          <tr>
                 <td style="font-size: small; width: 130px;">
                       Company Name:
                 </td>
                 <td style="font-size: small;">
                        <input name="CompanyName" type="text" value="" style="width: 280px" />
                 </td>
         </tr>
         <tr>
                <td style="font-size: small;">
                         Address:
               </td>
               <td style="font-size: small;">
                         <input name="Address" type="text"  value="" style="width: 280px" />
               </td>
          </tr>
          <tr>
                <td style="font-size: small;">
                          City, St, Zip:
                 </td>
                 <td style="font-size: small;">
                          <input name="City" type="text"  value=""  style="width: 120px" />
                              <select name="State" style="width: 55px">
                                    <option value="AK">AK</option>
                                      ...states
                               </select>
                           <input name="Zip"  value="" type="text" style="width: 93px" />
                  </td>
           </tr>
           <tr>
                  <td style="font-size: small;">
                             Phone:
                 </td>
                <td style="font-size: small;">
                            <input name="Phone"  value="" type="text" style="width: 280px" />
                 </td>
            </tr>
            <tr>
                 <td style="font-size: small;">
                             Contact:
                  </td>
                  <td style="font-size: small;">
                          <input name="Contact"  value="" type="text" style="width: 280px" />
                   </td>
             </tr>
             <tr>
                 <td style="font-size: small;">
                            &nbsp
                  </td>
                  <td align="right" style="font-size: small;">
                            <input name="cmdSubmit" type="submit" value="Submit" />
                  </td>
             </tr>
     </table>
 </form>

Open in new window


<html>
<head>
    <title>Message Sent</title>
</head>
<body>
    <%

        Dim name, address, city, state, zip, phone, contact
        name=request.form("CustomerName")
        address=request.form("Address")
        city=request.form("City")
        state=request.form("State")
        zip=request.form("Zip")
        phone=request.form("Phone")
        contact=request.form("Contact")

        'response.write contact
        'response.end


        Dim NewMailObj

        'create the mail object and send the details
        Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
        NewMailObj.From ="sam.okeh@keniginc.com"
        NewMailObj.To = "youremail.com"
        NewMailObj.Subject = "Customer signed up"
        NewMailObj.Body = "Customer Name: " & name & _
        "<br>Address: " & address & _
        "<br>City: " & city & _
        "<br>State: " & state & _
        "<br>Zip: " & zip & _
        "<br>Phone: " & phone & _
        "<br>Contact: " & contact

        'you need to add the following lines FOR the mail to be sent in HTML format
        NewMailObj.BodyFormat = 0
        NewMailObj.MailFormat = 0
        NewMailObj.Send
        'Close the email object and free up resources
        Set NewMailObj = nothing
        Response.write "The email was sent."
    %>
</body>
</html

Open in new window


It worked fine for me and I was able to receive emails.

Good luck. Let me know if you still run into issues - you shouldn't.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492900
sorry, forgot the attachment:

Ok, they don't allow zipand they don't allow the dll.

Here is the link. Click it and downlow the zip:

http://www.jppinto.com/resources/cdonts.zip


0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36492910
Ok, one more correction.

My fault - sorry.

I did it 2 different ways.

You can do it all in one page which is the first part I posted.

However, if you insist on doing it in 2 pages like you had it before, then use this page:

  <form method="post" action="IndexToMail.asp">    <table style="width: 420px;">
          <tr>
                 <td style="font-size: small; width: 130px;">
                       Company Name:
                 </td>
                 <td style="font-size: small;">
                        <input name="CompanyName" type="text" value="" style="width: 280px" />
                 </td>
         </tr>
         <tr>
                <td style="font-size: small;">
                         Address:
               </td>
               <td style="font-size: small;">
                         <input name="Address" type="text"  value="" style="width: 280px" />
               </td>
          </tr>
          <tr>
                <td style="font-size: small;">
                          City, St, Zip:
                 </td>
                 <td style="font-size: small;">
                          <input name="City" type="text"  value=""  style="width: 120px" />
                              <select name="State" style="width: 55px">
                                    <option value="AK">AK</option>
                                      ...states
                               </select>
                           <input name="Zip"  value="" type="text" style="width: 93px" />
                  </td>
           </tr>
           <tr>
                  <td style="font-size: small;">
                             Phone:
                 </td>
                <td style="font-size: small;">
                            <input name="Phone"  value="" type="text" style="width: 280px" />
                 </td>
            </tr>
            <tr>
                 <td style="font-size: small;">
                             Contact:
                  </td>
                  <td style="font-size: small;">
                          <input name="Contact"  value="" type="text" style="width: 280px" />
                   </td>
             </tr>
             <tr>
                 <td style="font-size: small;">
                            &nbsp
                  </td>
                  <td align="right" style="font-size: small;">
                            <input name="cmdSubmit" type="submit" value="Submit" />
                  </td>
             </tr>
     </table>
 </form>

Open in new window


and the second part of your file - the asp file is fine; use it

Sorry about any confusion.
0
 

Author Comment

by:md0333
ID: 36492954
OK... I would prefer to use one page. Do I need to change the extension to asp if I do that?

First things first tho... I dropped the dll in the C:\Windows\System32 directory and verified that it is there. I am getting an error when I try to register it.

RegSvr32
The module "c:\windows\system32\cdonts.dll" failed to load.
Make sure the binary is stored at the specified path or debug
it to check for problems with the binary or dependent .dll files.

The specified module could not be found.
0
 

Author Comment

by:md0333
ID: 36492977
should I add it to the C:\Windows\SysWOW64 folder and register it from there?
0
 

Author Comment

by:md0333
ID: 36492993
did that... the dll registered successfully. But still getting error.
0
 

Author Comment

by:md0333
ID: 36493023
Tried your one page version...

Telling me I'm missing "required action attribute in the form tag" and
•A request was sent to a virtual directory using the HTTP verb POST and the default document is a static file that does not support HTTP verbs other than GET or HEAD.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36493118
If you are using one page, then just this page and run it as is after giving it a name, let's say whatever.asp

I will stick around a little longer to see if I can help you get it working tonight.

    <%

        Dim name, address, city, state, zip, phone, contact
        name=request.form("CustomerName")
        address=request.form("Address")
        city=request.form("City")
        state=request.form("State")
        zip=request.form("Zip")
        phone=request.form("Phone")
        contact=request.form("Contact")

        'response.write contact
        'response.end


        Dim NewMailObj

        'create the mail object and send the details
        Set NewMailObj=Server.CreateObject("CDONTS.NewMail")
        NewMailObj.From =request.form("Contact")
        NewMailObj.To = "youremail.com"
        NewMailObj.Subject = "Customer signed up"
        NewMailObj.Body = "Customer Name: " & name & _
        "<br>Address: " & address & _
        "<br>City: " & city & _
        "<br>State: " & state & _
        "<br>Zip: " & zip & _
        "<br>Phone: " & phone & _
        "<br>Contact: " & contact

        'you need to add the following lines FOR the mail to be sent in HTML format
        NewMailObj.BodyFormat = 0
        NewMailObj.MailFormat = 0
        NewMailObj.Send
        'Close the email object and free up resources
        Set NewMailObj = nothing
        Response.write "The email was sent."
    %>
  <form method="post" id=form1 name=form1>
    <table style="width: 420px;">
          <tr>
                 <td style="font-size: small; width: 130px;">
                       Company Name:
                 </td>
                 <td style="font-size: small;">
                        <input name="CompanyName" type="text" value="" style="width: 280px" />
                 </td>
         </tr>
         <tr>
                <td style="font-size: small;">
                         Address:
               </td>
               <td style="font-size: small;">
                         <input name="Address" type="text"  value="" style="width: 280px" />
               </td>
          </tr>
          <tr>
                <td style="font-size: small;">
                          City, St, Zip:
                 </td>
                 <td style="font-size: small;">
                          <input name="City" type="text"  value=""  style="width: 120px" />
                              <select name="State" style="width: 55px">
                                    <option value="AK">AK</option>
                                      ...states
                               </select>
                           <input name="Zip"  value="" type="text" style="width: 93px" />
                  </td>
           </tr>
           <tr>
                  <td style="font-size: small;">
                             Phone:
                 </td>
                <td style="font-size: small;">
                            <input name="Phone"  value="" type="text" style="width: 280px" />
                 </td>
            </tr>
            <tr>
                 <td style="font-size: small;">
                             Contact:
                  </td>
                  <td style="font-size: small;">
                          <input name="Contact"  value="" type="text" style="width: 280px" />
                   </td>
             </tr>
             <tr>
                 <td style="font-size: small;">
                            &nbsp
                  </td>
                  <td align="right" style="font-size: small;">
                            <input name="cmdSubmit" type="submit" value="Submit" />
                  </td>
             </tr>
     </table>
 </form>

Open in new window


0
 

Author Comment

by:md0333
ID: 36493179
OK... pushed the page out to the server because I don't have cdonts.dll installed on the dev. I changed the name of the page to have an asp extension. When I try to open the page I get the following error.

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.


could there be a setting somewhere not allowing .asp extensions?
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36493197
Are you testing from same browser that we fixed?

If no, then fix the browser like we did earlier by unchecking "show http friendly error messages"

*BUT* if the browser has already been fixed, do you have access to the server?

If yes, then have you checked to see if:

a) iis is installe don the server
b) is smtp installed on the server?

c) if answer is yes to both questions, then try registering cdonts on that server and see what happens.
0
 

Author Comment

by:md0333
ID: 36493204
IIS is installed
SMTP is installed
cdonts is registered in the sysWOW64 directory... it would not register in system32
0
 

Author Comment

by:md0333
ID: 36493211
... and yes I'm using the same browser we fixed earlier
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36493223
Try this and let me know:

Under the IIS heading, open the ASP properties, and under Compilation, expand the Debugging Properties, there you'll find:

Send Errors To Browser

Set it to True

Then try running your app again.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 36493232
IF for some reason that doesn't give us meaningful error message, then try this as well.

In IIS, from properties to Error Pages -> 500 -> Edit Feature Settings -> "Detailed Erros"

Then try again
0
 

Author Comment

by:md0333
ID: 36493243
OK... the last one helped give me this error.

error '80070003'
/index-1.asp, line 242
0
 

Author Comment

by:md0333
ID: 36493261
OK... SMTP is intalled and we use email. But under IIS > ASP.Net settings > SMTP E-mail the settings are not set up. Do I need to do that so the cdonts will work?
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 36493265
Ok, try this link. It should guide you to fixing that problem:

http://support.microsoft.com/kb/238956

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now