ASP.NET makes it amazingly simple for you to send e-mails from a Web application or even a Web form.
First of all Create the following things -
1) A .aspx page using 2 Labels and 2 textbox and one Button.
We can use the following code :
——————————————–
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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.Security.Cryptography;
using System.Xml;
using System.Text;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSend_Click1(object sender, EventArgs e)
{
bool returnedValue = SendingMail(txtfrom.Text, txttext.Text);
if (returnedValue == true)
{
StringBuilder sb = new StringBuilder();
sb.Append(“”);
sb.Append(“alert(‘your mail has been send, we will contact you soon. Thank you.’);”);
sb.Append(“”);
Response.Write(sb.ToString());
}
else
{
txtfrom.Text = “”;
txtfrom.Focus();
}
}
private bool SendingMail(string from, string message)
{
try
{
MailMessage msg = new MailMessage(from, “checkmymail123@gmail.com”);
msg.Subject = “Contact Us”;
msg.Body = “Recieved From: ” + from + ” Message: ” + message;
msg.IsBodyHtml = true;
msg.BodyEncoding = Encoding.UTF32;
msg.Priority = MailPriority.Normal;
SmtpClient client;
client = new SmtpClient();
client.Host = “smtp.gmail.com”;
client.Port = 587;
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential(“checkmymail@gmail.com”, “password”);
client.Send(msg);
return true;
}
catch
{
return false;
}
}
}
————————————————–
This code is very helpful to use the gmail at ur Contact Us page. Means you can create the Contact US page easily.
with Regards
Dinesh Verma
+919718461838
+919896328595
Vermadenish@gmail.com