Nowadays, web masters prefer to receive information from their users or customers through a contact or feedback form placed on the website. ASP.NET 2.0 provides a simplified approach to achieve the task as compared to ASP.NET 1.1. In this part of the series, we will examine how to send e-mails in plain text and HTML formats using C#.
Let us start our discussion by creating a simple user interface as shown below
Figure 1
The code to create the above WebForm is given below.
<form id="Form1" runat="server">
<div align="left">
<table border="0" width="544">
<tr>
<td valign="top"><font face="Verdana" size="2">Name</font></td>
<td height="24" valign="top"> <asp:TextBox runat="server" Height="25px" Width="370px" ID="txtName"></asp:TextBox>
<asp:RequiredFieldValidator ID = "reqName" ControlToValidate = "txtName" Runat = "server" ErrorMessage = "*"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td valign="top"><font size="2" face="Verdana">Address</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="25px" Width="370px" ID="txtAddress"></asp:TextBox> </td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">From</font></td>
<td height="24" valign="top"> <asp:TextBox runat="server" Height="22px" Width="368px" ID="txtFrom"></asp:TextBox>
<asp:RequiredFieldValidator ID = "reqFrom1" ControlToValidate = "txtFrom" runat = "server" ErrorMessage = "*" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID = "regFrom2" ControlToValidate = "txtFrom" runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
<br></td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">To</font></td>
<td height="24" valign="top">
<asp:TextBox runat="server" Height="22px" Width="368px" ID="txtTo"></asp:TextBox>
<asp:RequiredFieldValidator ID = "reqTo1" ControlToValidate = "txtTo" runat = "server" ErrorMessage = "*" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID = "reqTo2" ControlToValidate = "txtTo" runat = "server" ErrorMessage = "Invalid Email" ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td valign="top"><font face="Verdana" size="2">Comments</font></td>
<td height="112" valign="top"><asp:TextBox runat="server" Height="110px" TextMode="MultiLine" Width="368px" ID="txtComments"></asp:TextBox>
<asp:RequiredFieldValidator ID = "reqComments" ControlToValidate = "txtComments" Runat = "server" ErrorMessage = "*"></asp:RequiredFieldValidator> </td>
</tr>
<tr>
<td colspan="2" valign="top" height="30">
<p align="center">
<asp:Button Runat = server ID = btnSubmit OnClick = btnSubmit_Click Text = "Submit"></asp:Button>
<input id="Reset1" type = "reset" runat = "server" value = "Clear"></td>
</tr>
</table>
</div>
<p> </p>
<p><br>
<!-- Insert content here -->
</p>
</form>