Old .NET form code not working on IIS7 with Framework 2.0/3.0/3.5

I have some code that I tweaked for a contact form that I have been using for years with no trouble. I recently upgraded my hosting account to IIS7 and upgraded the Framework and now my code isn’t working. I don’t know how to fix my code so that it works. Could someone look at it and tell me what I need to fix? I know it’s a lot of code and the person that originally wrote it for me many years ago was kind enough to comment everything so I knew what was going on but with the upgrade I have no idea what is incorrect. The error that I am getting when the form is filed out and submitted is…

A Problem prevented your request from being accepted: The “SendUsing” configuration value is invalid.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" %>
<!--Below we will import the .NET mail namespace.  This namespace contains all the email functionality you'll
need to do email autoresponders, notification, or other email messages you want your web page to generate automatically.-->
<%@ Import Namespace="System.Web.Mail" %>
<script runat="server">

Sub Submit_Click(o as Object, e as EventArgs)
'This subroutine will handle the email portion of the form.
'The details will be explained in the comments below

'The first thing we must do is declare or "Dimension" the variables we will use.  We will declare variables for each form field,
'and we will insert those variables into the text of the email message.
Dim strName as String = txtName.Text 'This will assign the text of the "Name" textbox to this variable
Dim strEmail as String = txtEmail.Text 'This will assign the text of the "Email" textbox to this variable
Dim strCity as String = txtCity.Text 'This will assign the text of the "City" textbox to this variable
Dim strState as String = txtState.Text 'This will assign the text of the "State" textbox to this variable
Dim strZip as String = txtZip.Text 'This will assign the text of the "Zip" textbox to this variable
Dim strCountry as String = txtCountry.Text 'This will assign the text of the "Country" textbox to this variable
Dim strRequest as String = txtRequest.Text 'This will assign the text of the "Request" textbox to this variable
Dim oMsg as New MailMessage 'This will create the Mail Message object that will send the form results to you via email
Dim strBody as String 'This will be a string value that we will construct below to create the HTML email message

	If Not IsValid() then 'Because we are using validation controls, we have to check to see if the form is filled out properly
		Exit Sub 'If the form isn't right, then we don't want to do anything further, so we'll exit this subroutine
	end if
' 	ASP.NET uses the "Try-Catch" method of handling errors that may occur when the code runs.  The "Try" phrase instructs the .NET framework
'	to run some code.  If an error pops up, the "Catch" line gives the instructions on what you want the page to do if an error is thrown
' 	So, we'll start off with the "Try" and that will include all the code needed to send the mail message
		'First we'll clear out the lblErr control, just in case there's text in it we don't want
		lblErr.text = ""
		'Now, we'll build the text string that contains the text and the HTML to format our email message
		strBody = "A New visitor has requested information on a website at Foxden Web Solutions.  The following information was submitted:<br /><br />" & _
		 "<strong>Visitor Name:<strong /> " & strName & "<br />" & _
		 "<strong>Email Address:<strong /> " & strEmail & "<br />" & _
		 "<strong>City:<strong /> " & strCity & "<br />" & _
		 "<strong>State:<strong /> " & strState & "<br />" & _
		 "<strong>Zip Code:<strong /> " & strZip & "<br />" & _
		 "<strong>Country:<strong /> " & strCountry & "<br />" & _
		 "<strong>Request:<strong /> " & strRequest & "<br />"

		oMsg.From = strEmail 'This will use the email address the user provided as the "From" Address for the mail message
		oMsg.To = "CoriFoxworthy@foxdenwebsolutions.com" 'This is the address to which the mail message will be sent
		oMsg.Subject = "New Website Request from Foxden Web Solutions" 'This is the subject of the mail message
		oMsg.Body = strBody 'The string value we created above will be the message body for this email
		oMsg.BodyFormat = MailFormat.HTML 'This make the message an HTML email.  If you don'r specify this, the message will be 
		                                  'sent as plain text
		SmtpMail.Send(oMsg) 'This notifies the .NET Framwork's email class to send the message we just constructed.
	Catch Exc as Exception 'Now we have to catch the error, and the "Exc" variable is an instance of the Exception Object
		lblErr.text = "A Problem prevented your request from being accepted: " & Exc.Message
	End Try 'This lets the Framework know that the Try is complete
End Sub
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Parker CO WEB DESIGN|Denver CO WEB DESIGN|Foxden Web Solutions - Contact us to if you are interested in a website.</title>
<meta name="keywords"  content="Parker CO, Web Design, parker co web design, web design, affordable web design, denver web design, colorado web design" />
<meta name="description" content="Contact Foxden Web Solutions today for a quote on your online presence." />
<link rel="stylesheet" type="text/css" href="css/newfoxden.css" media="all" />
<!--[if IE]>
<style type="text/css" media="all">.borderitem {border-style:solid;}</style>
<!--[if IE]>
<style type="text/css"> 
#footer, { zoom: 1;}
<div id="header_container">
  <div id="header">
    <h1>Foxden Web Solutions Contact Us</h1>
<div id="nav_bg">
    <ul class="menu">
      <li class="home"><a href="index.html"  title="Home"><span class="displace">Home</span></a></li>
      <li class="history"><a href="history.html" title="History"><span class="displace">History</span></a></li>
      <li class="help"><a href="help.html" title="How Can We Help?"><span class="displace">How Can We Help?</span></a></li>
      <li class="price"><a href="price.html" title="Design Pricing"><span class="displace">Design Pricing</span></a></li>
      <li class="portfolio"><a href="portfolio.html" title="Portfolio"><span class="displace">Portfolio</span></a></li>
      <li class="contact"><a href="#" class="selected" title="Contact"><span class="displace">Contact</span></a></li>
      <li class="blog"><a href="blog.html" title="Blog"><span class="displace">Blog</span></a></li></ul>
<div id="main_container">
  <div id="content_top"></div>
  <div id="content_mdl">
    <div id="form">
      <p>If you would like to contact me for information about a website, please fill in the contact form below. I will respond back as quickly as I can.</p>
      <form runat="server">
        <asp:label TextColor="#C0BDAC" ID="lblErr" runat="server"></asp:label>
        <legend>Contact Details</legend>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="name">Full Name:</label> 
            <asp:textbox Columns="30" ID="txtName" runat="server" />
							   ControlToValidate="txtName" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="email">Email address:</label>
            <asp:textbox Columns="30" ID="txtEmail" runat="server" />
							   ControlToValidate="txtEmail" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="city">City/Town:</label>
            <asp:textbox Columns="30" ID="txtCity" runat="server" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="state">State/Province:</label>
            <asp:textbox Columns="30" ID="txtState" runat="server" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="zipcode">Zip Code/Postal Code:</label>
            <asp:textbox Columns="30" ID="txtZip" runat="server" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="country">Country:</label>
            <asp:textbox Columns="30" ID="txtCountry" runat="server" />
            <label for="request">Website Information Request:</label>
            <asp:textbox Columns="40" ID="txtRequest" Rows="5" runat="server" TextMode="MultiLine" />
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:button ID="btnSubmit" Text="Submit"  runat="server" OnClick="Submit_Click" />        
          <input type="reset" name="Reset" value="Reset" />
  <div id="content_btm"> </div>
  <div id="footer">
    <p> Copyright &copy; 2010 Foxden Web Solutions </p>
            <!-- Start of StatCounter Code -->
            <div align="center">
                <script type="text/javascript">
var sc_project=891624; 
var sc_invisible=1; 
var sc_security="2bd1683e"; 
                <script type="text/javascript"
class="statcounter"><a title="statistics in vBulletin"
alt="statistics in vBulletin" /></a></div>
            <!-- End of StatCounter Code -->
    <div id="footer_nav">
        <li><a href="index.html">Home</a> | <a href="history.html">History</a> | <a href="help.html">How can we help?</a> | <a href="pricing.html">Design Pricing</a> | <a href="portfolio.html">Portfolio</a> | <a href="contact.aspx">Contact</a> | <a href="blog.html">Blog</a></li>
  <!--//end of footer-->

Maybe I am blind, but where do you add your SMPT Server declaration? If you moved it to a new server, you need to find out the Server IP/name, and change it accordingly, so you can send an email.

I don’t believe that was ever in the code but it always worked properly with IIS 5.x and Framework 1.1

The problem started when I upgraded to IIS7 and Framework 2.0/3.0/3.5

Is the SMTP configuration in the Web.Config file?

This is my Web.config code -

<!-- Web.Config Configuration File –>

<customErrors mode=“Off”/>

I don’t know if this will be much help, but I did a search for “smtpmail sendusing” and it looks like you may need to assign a value to SmtpMail’s SmtpServer property. eg.

SmtpMail.SmtpServer = "mail.your-domain.com"

I am not sure where I should put this code.

Well, first thing to do is to install 1.1 on the Win2008 box–it isn’t there by default.

I am running Windows 7 on my laptop with Framework 2.0/3.5 installed and IIS7 installed. I am not running this locally though. I know that this should be my test setup but I really don’t want to mess with it because I have never been able to enable mail being sent when I test.

I will have my site as my test site to make sure things are running properly.

I would try putting it before

SmtpMail.Send(oMsg) 'This notifies the .NET Framwork's email class to send the message we just constructed.

Although I imagine the tricky part is finding out the correct value to use for “mail.your-domain.com”. Hopefully you can find it in your account’s ACP, or your host’s Wiki or Support forum easily enough so you won’t need to file a support ticket and have to wait to try it.

Ok I found what their server is -


Added the code and tested - now I get this error -

A Problem prevented your request from being accepted: The server rejected the sender address. The server response was: 553 sorry, your mail was administratively denied. (#5.7.1)

Interesting, this is the relay server they told me to use.


You say it is running on your local host? What is the hostname of the SMTP server? If it is localhost, you would need to configure your PC to send out emails. If it is not localhost and points to a live mail server, check with them what permissions have been granted. As I am sure they will not allow mails to be sent from ur local PC and only from your production server.

Also, at some stage, I would suggest upgrading to the System.Net.Mail namespace as opposed to the System.Web.Mail you’re using at the moment. It is a better way of sending mail

@NightStalker-DNS, I thought he was testing on the live server, but yes, trying to use the live server’s email remotely would most likely be not allowed.

My guess is that you either need to make sure the “From” is using the same domain as the server (which it really is after all, it’s not “from” whoever@whatever.com, it’s from the server’s form, the user’s email is their email address, not where it’s coming from).

Or you need a way to tell the script to
Use Authentication, and
Use to-be supplied login information.

So, if you try the form using something like test@secureserver.net does it work?

You are right. Maybe it has something to do with the web.mail namespace, as it was depreciated in .net 2.0 already. Only other thing can be SMTP settings on the server. Also could possibly, be a firewall.

Second that. First thing you need to do is find out what is using Port 80. Simple browser search will help you with that. Anyways, your code looks right, and the code given above should solve your problem if it was a coding problem, but it sounds like another service is using the port, could be an anti-virus program, or as stated above, a firewall.

Last time I checked, SMTP generally ran on port 25 not 80 (http) . . .

Yeah, I just realized your declaration should be “System.Net.Mail”, and not “System.Web.Mail”

EDIT: Sorry for the Port confusion, I was wrong. I keep getting that port confused with other Server ports.

^^^Not in 1.1, System.Net.Mail was added in 2.0.

Did you read that the OP updated his app to 2.0? That’s why I advised he update his include to the 2.0/3.5 namespace.

I changed System.Web.Mail to System.Net.Mail and get a compilation error. As stated before I am NOT testing this locally and trying to get the email sent through my hosting server. I am testing on my actual site. I do not believe I have the access to change ports or anything else except my code. Please understand this! My code was working before I upgraded my HOSTING ACCOUNT to IIS7 running Framework 2.0/3.0/3.5. My account WAS using IIS5.x with Framework 1.1 and the form worked just fine BEFORE the upgrade. I upgraded so I could use PHP if I wanted to.

Here is the compilation errer -
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: BC30311: Value of type ‘String’ cannot be converted to ‘System.Net.Mail.MailAddress’.

Source Error:

Line 45: "<strong>Request:<strong /> " & strRequest & “<br />”
Line 46:
Line 47: oMsg.From = strEmail 'This will use the email address the user provided as the “From” Address for the mail message
Line 48: oMsg.To = “CoriFoxworthy@foxdenwebsolutions.com” 'This is the address to which the mail message will be sent
Line 49: oMsg.Subject = “New Website Request from Foxden Web Solutions” 'This is the subject of the mail message