C# Code:
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.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Globalization;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Specify senders gmail address
string SendersAddress = "[email protected]";
//Specify The Address You want to sent Email To(can be any valid email address)
string ReceiversAddress = "[email protected]";
//Specify The password of gmial account u are using to sent mail(pw of [email protected])
const string SendersPassword = "Password";
//Write the subject of ur mail
string subject = "ENQUIRY FORM";
//Write the contents of your mail
string body = "Subject : " + txtSub.Text + "\nName : " + txtName.Text + "\nMobile : " + txtMobile.Text + "\nE-mail : " + txtEmail.Text + "\nField : " + drpdwnlstFields.Text + "\nMessage : " + multtxtMessage.Text;
try
{
//we will use Smtp client which allows us to send email using SMTP Protocol
//i have specified the properties of SmtpClient smtp within{}
//gmails smtp server name is smtp.gmail.com and port number is 587
SmtpClient smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 25,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential(SendersAddress, SendersPassword),
Timeout = 999999
};
//MailMessage represents a mail message
//it is 4 parameters(From,TO,subject,body)
MailMessage message = (new MailMessage(SendersAddress, ReceiversAddress, subject, body));
/*WE use smtp sever we specified above to send the message(MailMessage message)*/
smtp.Send(message);
lblResponse.Text = "Your query has been submitted successfully, We will get back to you shortly.";
}
catch (Exception ex)
{
lblResponse.Text = "Sorry server busy, Please try again later.";
}
Response.Redirect("Home");
}
protected void btnReset_Click(object sender, EventArgs e)
{
Response.Redirect(Request.Url.PathAndQuery, true);
}
}
WebConfig Code :
port="25"
defaultCredentials="false"
enableSsl="true"
/>

Vithal WadjePosted Mar 24, 2015, 2:02 PM