using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.IsBodyHtml = true;
mail.From = new MailAddress("Your Email address"); // from which email address you want to configure
mail.To.Add("recipient email address"); // to whom you need to send
mail.Subject = "Customer Inquiry"; // subject
mail.Body = "Name :" + TextBox1.Text + "Email: " + TextBox2.Text + "Phone No: " +TextBox3.Text + "Country: " + TextBox4.Text + "Enquiry: " +TextBox5.Text; // contact form details
SmtpServer.Port = 587; //465
SmtpServer.Credentials = new System.Net.NetworkCredential("your email address", "email password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
lblMessage.Text = "Enquiry has been sent";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message.ToString();
}
}
}
//Then you must need to configure web.config file as follows close all tags
< mailSettings >
< smtp >
< network host="smtp.gmail.com" port="587" />