Mail Function in ASP.NET using C#

Hi all,
I’m a PHP developer now into ASP.NET using C#, i designed a form which when submitted sends an email to the of i’m a newbie, i#m unable to understand the C# here. can anyone please help me out…
I’m now getting RELAY response from the SMTP when i set smtp server as localhost.

here’s my c# code, please do help me…

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;

namespace tc.conferencing._contact_us
    public partial class conferencing_contactus : System.Web.UI.Page

        protected void Page_Load(object sender, EventArgs e)


        protected void Button_Click(object sender, EventArgs e)

        private void SendMail()
            MailMessage mail = new MailMessage();
            mail.To = "";
            mail.From = "";
            mail.Subject = "HI";
            mail.Body = "Online Enquiry Test Form";
            label.Text = "Please Wait...";
            SmtpMail.SmtpServer = "localhost";
            label.Text = "Your Enquiry Has Been Submitted, We will Get Back to you sooner.";


here’s my .aspx page:

<tr><td class="main2"><strong>Enquiry Form</strong></td></tr>
			  <tr><td class="main2"></td></tr>			
			  <tr><td class="main2">Please use the form below to fill in your details and a detailed information about your enquiry. One of our staff will be in touch with you as soon as possible.</td></tr>			
			  <tr><td class="main2">Alternatively you may wish to telephone us directly, to do so please use the links on the left hand side to go to our branch details where we have telephone, fax and direct email addresses.</td></tr>			  			
			  <tr><td class="main2"></td></tr>			  			
			  <tr><td class="main2" valign="top">
			  <table cellpadding="0" cellspacing="5" width="100%" class="main2">
  			  <tr><td align="right">Title</td><td align="left">
                                                    <asp:DropDownList class="ClassicTxtField" ID="Title"  name="Title" runat="server" Height="18px" Width="58px">
                                                        <asp:ListItem Value="Mr."></asp:ListItem>
                                                        <asp:ListItem Value="Mrs."></asp:ListItem>
                                                        <asp:ListItem Value="Ms."></asp:ListItem>
                                                        <asp:ListItem Value="Miss."></asp:ListItem>
			  <tr><td align="right">First Name</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="FirstName"  name="FirstName" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">Last Name</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="LastName"  name="LastName" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">Address Line 1</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="AddressLine1"  name="AddressLine1" runat="server" Height="18px" Width="214px"></asp:TextBox>
			  <tr><td align="right"></td><td align="left">
                  <asp:TextBox class="ClassicTxtField" ID="AddressLine2"  name="AddressLine2" runat="server" Height="18px" Width="214px"></asp:TextBox>
			  <tr><td align="right">Town</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="Town"  name="Town" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">Postcode</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="Postcode"  name="Postcode" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">County</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="County"  name="County" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">Country</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="Country" name="Country" runat="server" Height="18px" Width="154px"></asp:TextBox>
			  <tr><td align="right">Enquiry Subject Line</td><td align="left">
                                                    <asp:TextBox class="ClassicTxtField" ID="Subject" name="Subject" runat="server" Height="18px" Width="352px"></asp:TextBox>
			  <tr><td align="right" valign="top">Your Enquiry</td><td align="left" valign="top"><textarea runat="server" id="Message" class="ClassicTxtField" rows="15" cols="60" name="Message"></textarea>*</td></tr>			  			  			
			  <tr><td align="right"></td><td align="left">
                  <asp:Button ID="Button" class="ClassicButton" runat="server" Height="18px" Text="Submit Your Enquiry"
                      Width="202px" onclick="Button_Click" />

i’m trying to show user a label ‘mail sent’ when button click event performed successfully, else an error message.
can anyone pls give me an idea how to proceed…
many thanks

Code looks about right to me. Your localhost is probably not configured correctly. Is it ur machine or host? Check the mailroot folder in inetpub folder and check for your mail there.

Also, i would suggest looking int System.Net.Mail instead of web. Its a lot better.

Code looks about right to me. Your localhost is probably not configured correctly. Is it ur machine or host? Check the mailroot folder in inetpub folder and check for your mail there.

I configured my localhost added in RELAY.
when i checked my mailroot folder i can see all my mails in Badmail folder…

Also, i would suggest looking int System.Net.Mail instead of web. Its a lot better.

I did this, but i got few errors like no defenition for SmtpMail.send(mail) in System.Net.Mail

My general Question:
i’m a professional php programmer, in how many days cal i excel .net technologies? please let me know, as i’m having less exposure to OO Programming.
Many Thanks.

That is working well when uploaded to the server.
My doubt is, i would now like to display a success or error message on top of the form for, if an email was sent or not.
How should i do this? can anyone please help me out…
Above is my C# code, i need to display Success Message in the form if all goes fine else error in GREEN color.

Why do not you try sending emails using SMTP authentication using SmtpClient class??

Just put a div on the page where ever u want the message to appear. Make it runat server and give it an id. and make visible=“false”

Then on success just divID.Visible = true. divID.InnerHtml = “Email has been sent”;

Just after the SmptClient.Send() method.

It could not be going out from local host as its a spam IP address. Wen i test in our local office, it doesnt work and I checked and my IP was on a spam list. But always works fine on live server