private string PopulateBody(string userName, string phone, string email, string message) { string body = string.Empty; using (System.IO.StreamReader reader = new System.IO.StreamReader(Server.MapPath("~/bodyPage.htm"))) { body = reader.ReadToEnd(); } body = body.Replace("{Name}", userName); body = body.Replace("{Phoneno}", phone); body = body.Replace("{Email}", email); body = body.Replace("{Message}", message); return body; } protected void btnSubmit_Click(object sender, EventArgs e) { try { MailMessage Msg = new MailMessage(); // Sender e-mail address. Msg.From = new MailAddress(txtEmail.Text); // Recipient e-mail address. Msg.To.Add("info@dhuvara.com"); Msg.Subject = txtEmail.Text; string message = PopulateBody(txtName.Text,txtphone.Text,txtEmail.Text,txtMessage.Text); Msg.Body = message; Msg.CC.Add("baskey2@gmail.com"); Msg.IsBodyHtml = true; // your remote SMTP server IP. SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.live.com"; smtp.Port = 587; Msg.Priority = MailPriority.Normal; smtp.UseDefaultCredentials = false; smtp.Credentials = new System.Net.NetworkCredential("info@dhuvara.com", "SolaiMail"); smtp.EnableSsl = true; smtp.Send(Msg); //Msg = null; lbltxt.Text = "Thanks for Contact us"; // Clear the textbox valuess txtName.Text = ""; // txtSubject.Text = ""; txtMessage.Text = ""; txtEmail.Text = ""; } catch (Exception ex) { Console.WriteLine("{0} Exception caught.", ex.ToString()); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)