sending email through asp.net application(contact/feedback form eg.)

Ankitsrist
Posted by Ankitsrist under ASP.NET category on | Points: 40 | Views : 4539
hey frnds,
here i will explain how to make contact form as we generaly see on various websites....it is very simple, copy paste below .aspx code

<%@ Page Language="C#" MasterPageFile="~/nationalmaster.master" AutoEventWireup="true" CodeFile="complaint form.aspx.cs" Inherits="complaint_form" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
email &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<asp:TextBox ID="TextBox2"
runat="server"></asp:TextBox>&nbsp;
<br />
<br />
subject &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
<br />
body &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
<asp:TextBox ID="TextBox4" runat="server" Height="100px" Width="205px"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</asp:Content>


below is code separation page aspx.cs page

using System.Net.Mail;
using System.Data.SqlClient;

public partial class complaint_form : System.Web.UI.Page
{
dbClass db = new dbClass();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
db.myconnection();
MailMessage msg = new MailMessage();
msg.From = new MailAddress("recipientmailid@rediffmail.com");
msg.To.Add("recipientmailid@india.com");
msg.Subject = TextBox3.Text;
msg.Body = "sender name:" + TextBox1.Text + "<break>sender email:" + TextBox2.Text + "<break>sender subject:" + TextBox3.Text + "<break>sender body:" + TextBox4;
SmtpClient smtp=new SmtpClient();
smtp.Host ="smtp.gmail.com";
smtp.Port=587;
smtp.Credentials =new System.Net .NetworkCredential("uremailid@gmail.com", "ur password");
smtp.EnableSsl =true ;
smtp.Send(msg);


}
}

njoy frnds
ankit saxena
ankitsaxena2011@india.com

Comments or Responses

Login to post response