public string mailbody() { string strbody=""; strbody+="<html>"; strbody+="<body>"; strbody += "<form id = form1 method=get action=\"url here\">"; strbody += "Name: <input type=text name=\"a\" /><br />"; strbody+="Age: <input type=text name=\"b\" /><br />"; strbody += "Location: <input type=text name=\"c\" /><br />"; strbody+="<input type=submit value=submit id=btnSend/><input type=reset />"; strbody+="</form>"; strbody += "</html>"; strbody += "</body>"; return strbody; } protected void btnSendMail_Click(object sender, EventArgs e) { try { string body; body = mailbody(); MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress(txtEmail.Text)); //To Email address msg.From = new MailAddress("siddhesh.patankar5189@gmail.com"); //from email address msg.Body = body; msg.IsBodyHtml = true; SmtpClient smp = new SmtpClient(); smp.Host = "smtp.gmail.com"; smp.Port = 587; smp.UseDefaultCredentials = true; smp.Credentials = new System.Net.NetworkCredential("", ""); //userid, password smp.EnableSsl = true; smp.Send(msg); status.InnerText = "Mail Sent"; //Response.Write("Mail Sent"); } catch (Exception ex) { status.InnerText = "Mail Not sent"; //Response.Write(ex.Message); } } Processing the data given by receiver and sending the email back public partial class index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string name; string age,location; string body; name=Request.QueryString["a"]; age=Request.QueryString["b"]; location=Request.QueryString["c"]; body=mailbody(name,age,location); ///Response.Write(name + "<br />"); ///Response.Write(age + "<br />"); ///Response.Write(location + "<br />"); try { MailMessage msg = new MailMessage(); msg.To.Add(new MailAddress("feedbackform123@gmail.com")); //mail to msg.From = new MailAddress("feedbackform123@gmail.com"); //mail from msg.Body = body; msg.IsBodyHtml = true; SmtpClient smp = new SmtpClient(); smp.Host = "smtp.gmail.com"; smp.Port = 587; smp.UseDefaultCredentials = true; smp.Credentials = new System.Net.NetworkCredential("", ""); //userid passwd smp.EnableSsl = true; smp.Send(msg); string sScript = ""; sScript += "<script language=\"javascript\" type=\"text/javascript\">\n"; sScript += "alert(' Your Mail has been sent successfully ')\n"; sScript += "window.close()"; sScript += "</script>"; run.InnerHtml = sScript; run.Visible = true; //Response.Write("Mail Sent"); } catch (Exception ex) { Response.Write(ex.Message); } } public string mailbody(string name,string age,string location) { string mbody; mbody=""; mbody+="Name:" + name + "<br />"; mbody+="Age:" + age + "<br />"; mbody+="Location:" + location + "<br />"; return mbody; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)